regex

Regular expression to put <P> AND <ul>/<ol> into array

I'm searching for a function in PHP to put every paragraph element like <p>, <ul> and <ol> into an array. So that i can manipulate the paragraph, like displayen the first two paragraphs and hiding the others. This function does the trick for the p-element. How can i adjust the regexp to also match the ul and ol? My tryout gives an err...

Reading numbers from string in C#

What I want? I want to display weather information on my page. I want to display the result in the browser specific culture. What am I doing? I use MSN RSS for this purpose. MSN returns the report in XML format. I parse the XML and display results. What problem am I facing? When displaying the report, I have to parse an XML no...

When's an Apostrophe not an Apostrophe - validation .Net / Javascript

I have an regular expression validator for emails in .NET 2.0 which uses client side validation (javascript). The current expression is "\w+([-+.']\w+)@\w+([-.]\w+).\w+([-.]\w+)" which works for my needs (or so I thought). However I was getting a problem with apostrophes as I had copy/pasted an email address from Outlook into the forms...

Regular Expression to divide 5.55FIX as 5.55 and FIX

I need to parse a String having entry 5.55FIX, 5.55 Variable, 5.55Float. I need to extract the decimal value and the string as separate. please suggest? ...

Use preg_match to find if string contains script-tags

Hello, How do I write a pattern to use with PHP's preg_match function to check if a string containing script-tags? ...

How do I extract single characters or enclosed groupings from a string in Perl?

I would like to split the string: "Hello[You]All" to the following array: H,e,l,l,o,[You],A,l,l I tried to do it with split: my $str = "Hello[You]All"; my @list = split(/(\[.*?\]|.)/, $str); foreach (@list) { print "->$_\n"; } Since I tried something that split is not supposed to do, it gave me the following array: ,H,,e,...

Regular Expression to find a string included between two characters, while EXCLUDING the delimiters

Hi all, I looked around for a while, but probably I can't "Google" with the proper keywords, so I'm asking here. I need to extract from a string a set of characters which are included between two delimiters, without returning the delimiters themselves. I'm trying to do it with C# RegEx object. A simple example should be helpful: Target...

How to set ignorecase flag for part of regular expression in Python?

Is it possible to implement in Python something like this simple one: #!/usr/bin/perl my $a = 'Use HELLO1 code'; if($a =~ /(?i:use)\s+([A-Z0-9]+)\s+(?i:code)/){ print "$1\n"; } Letters of token in the middle of string are always capital. Letters of the rest of words can have any case (USE, use, Use, CODE, code, Code and so on) ...

How do I get Vim to match a line not beginning with a seven-digit number?

I have a file with about 1000 lines. All lines begin with a seven-digit number except for the occasional line. I need to catch these lines and actually join them with the previous line. I've managed to be able to match any line that begins with a seven-digit number by using the following regex pattern: ^\d\{7} I can't seem to get it ...

where can i get regex for US / Canadian / Western Europe Postal Code, address, phone, fax etc ?

so im looking for a regex or some solution to detect street address, phone, fax etc in western countries. i know it wont be perfect, but still my priority is on US and Canadian street addresses, province/state, postal code and etc.... it would be nice if someone went out and did this already, instead of me rewriting the regex... thank...

regex not detecting space in username textbox

Hi all I have a asp:textbox taking a Username that is part of a Signup form for a new user account. Obviously I don't want the user to sign up using a space as a name so I have this regular expression which should keep the valid entry to ASCII characters between 3 and 16 in length with NO SPACES. but the no spaces doesn't work in prac...

Renaming contents of text file using Regular Expressions

I have a text file with several lines in the following format: gatename #outputs #inputs list_of_inputs_separated_by_spaces * gate_id example: nand 3 2 10 11 * G0 (The two inputs to the nand gate are 10 and 11) or 2 1 10 * G1 (The only input to the or gate is gate 10) What I need to do is rename the contents such that I eliminate th...

Specifying a callback function in preg_replace_callback?

I have some code like this (this is a simplified example): function callback_func($matches) { return $matches[0] . "some other stuff"; } function other_func($text) { $out = "<li>"; preg_replace_callback("/_[a-zA-Z]*/","callback_func",$desc); $out .= $desc ."</li> \r\n"; return $out; } echo other_func("This is a _test"); ...

Date Regular Expression

Hi all, I'm using a date field checker but I want to change the regex from DD-MM-YYYY to DD/MM/YYYY but I can't seem to get it working.. Here's the snippet of code: "date": { "regex": "/^[0-9]{1,2}\-\[0-9]{1,2}\-\[0-9]{4}$/", "alertText": "* Invalid date, must be in DD/MM/YYYY format" }, I'm sure it's quite simple but I have no i...

Email address validation, again...

Looking at the posts here for email address validation, I am looking to be much more liberal about the client side test I am performing. The closest I have seen so far is: ^([\w-\.]+)@((\[[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.)|(([\w-]+\.)+)) ([a-zA-Z]{2,4}|[0–9]{1,3})(\]?)$ That will not match this#[email protected], which according to R...

How to compress this function to short in Regex?

private string AccessToSQL(string accessString) { accessString = Regex.Replace(accessString, "dbo_", String.Empty); accessString = Regex.Replace(accessString, "\"", "'"); accessString = Regex.Replace(accessString, "%START%", startDate); accessString = Regex.Replace(accessString, "%STOP%", endDate); string midToSu...

Regex to match the first ending HTMl tag

I am trying to write a regex which match the first ending form tag. <form.*name="loginForm".*>[^~]*</form> The above regex matches till the second from ends i.e till line 8. but I want a regex that matches the immediate ending from tag in the below example it should match line 5. <html> <body> <form method = "post" name="loginFo...

A regular expression for \b

I am writing regular expressions for unicode text in Java. However for the particular script that I am using - Devanagari (0900 - 097F) there is a problem with word boundaries. \b matches characters which are dependent vowels(like 093E-094C) as they are treated like space characters. Example: Suppose I have the string: "कमल कमाल कम्हल क...

Regular Expression to find querystring portion of a hyperlink

I'm pretty new to regular expressions, but I'm sure a regex would give me something much more elegant than anything I could do with string methods. I've got a hyperlink in the form of: <a href="http://server.com/default.aspx?abc=123"&gt;hello&lt;/a&gt; I want to yank out just the querystring portion. Also, what's a good reference fo...

excluding matching characters in regular expression

I'm stuck with a regular expression problem. I've got a string which I need to match. The string always starts with 2 letters, and then is followed by a 6 digit number, e.g. EF123456 AB123456 However, there is one combination of letters which I need to ignore. e.g.: XX123456 So I want to write a regular expression to match only ...