regex

How do I say "not" using a regex when extracting a group of text?

I am trying to extract a section of text that looks something like this: Thing 2A blah blah Thing 2A blah blah Thing 3 Where the "3" above could actually be ANY single digit. The code I have that doesn't work is: ((Thing\s2A).+?(Thing\s\d)) Since the 3 could be any single digit, I cannot simply replace the "\d" with "3". I tried t...

PHP preg_match_all html

how can i create a preg_match_all regex pattern for php to give me this code? <td class="class2">&nbsp;</td> <td class="class2" align="right"><span class="DarkText">I WANT THIS TEXT</span></td> To get me the text inside the span class? thanks! ...

Regular expression for a hostname

I'm trying to match a hostname similar to foo-bar3-vm.companyname.local. The part that is foo-bar3 can be any combination of letters, numbers, and hyphens, but I want to ensure it ends in -vm.companyname.local. I was attempting to use /^[a-zA-Z0-9\-]*[vmVM]*\.companynanme\.local$/, but that seems to match anything ending in .companynam...

Need regular expression expert: round bracket within stringliteral...

I'm searching for strings within strings using Regex. The pattern is a string literal that ends in (, e.g. # pattern " before the bracket (" # string this text is before the bracket (and this text is inside) and this text is after the bracket I know the pattern will work if I escape the character with a backslash, i.e.: # pattern " ...

Python: compiling regexp problems

I have a interesting problem. I have a list of lists, and I want all except the first element of each list compiled into a regular expression. And then put back into the list. The lists start as strings. The following code doesn't work. It doesn't raise an error, it just doesn't seem to do anything. I think I have identified the problem...

How to use multi-line and look-ahead together in Textmate find function with regular expressions?

I've got a XML file and I need to locate all parameters with parameterid named aspect (or name field with Aspect as the value), find the end of the parameter, insert than another similar parameter called linewidth (see below for the aspect parameter <parameter> <parameterid>aspect</parameterid> <name>Aspect</name> <valuemin>0...

Reg. exp. in javascript to get last <a> tag in substring

Hi, I need to find the text of the last <a> tag in a page using javascript. I read the full HTML like this: var str = document.body.innerHTML; I now need to find a subpart of the str and inside that subpart i need to find the last <a> tag. There could be more than on <a> tag, but the exact count will be different. Here is an example...

How do I use Perl's smart matching to match many patterns at once?

I was trying to follow some examples to use smart matching in the following piece of code, but failed (nothing was filtered out). my $regexes_to_filter_a = ("tmp", "temp", "del") my @organism_dirs = (); # this will hold final list of dirs to processs my @subdirs = File::Find::Rule->directory->maxdepth(1)->in($root_dir); foreach my $sub...

javascript regex rule problem

function checkVideoUrl(url){ var regex= [],urlmatch= false; regex[0] = /http:\/\/www.56.com\/\S+\/([^\/]+).html/i; for(i=0;i<regex.length;i++){ urlmatch =regex[i].test(url); if(urlmatch == true) break; } return urlmatch; } alert(checkVideoUrl('http://www.56.com/w68/album-aid-8529817.html'));//true alert...

Trying to replace all white space with a single space.

Any ideas? My program is a file validation utility and I have to read in a format file then parse out each line by a single space. But obviously, the person who wrote the format file may use tabs, or 2 spaces, or any form of whitespace, and I'm looking for some code to do that. I've tried this: public static string RemoveWhit...

How to remove an entire line which matches a pattern

The following pattern matches an entire line, how do I search and remove these lines. If I leave a space in the replace string, it leaves a blank in that particular line, when I do via eclipse. ^[\t ]*<param name="logic" .*$ ...

Python String split with multiple regex

Hi I have Python String as shown below: <html><table border = 1><tr><td>JDICOM</td><td>Thu Sep 16 10:13:34 CDT 2010</td></tr></html> From above string I am interested in two words JDICOM Thu Sep 16 10:13:34 CDT 2010 I tried find, findall, split but it did not help because of multiple regex. I am quite new to python. If anyone kno...

regular expression help which includes "." in word sepration

expr = "name + partner_id.country_id.name + city + ' ' + 123 + '123' + 12*2/58%45" print re.findall('\w+[.]',expr) ['name', 'partner_id', 'country_id', 'name', 'city', '123', '123', '12', '2', '58', '45'] I want to include "." so result should be like ['name', 'partner_id.country_id.name', 'city', '123', '123', '12',...

Reading in certain lines of a text file

Yes, I have already asked this question, but the problem is much more specific. Last time I wanted to ignore the first 2 and the last line of the file. But it struck me that anyone could put as many lines as they wanted before and after the stuff I want to read in, and in that case, the code I've implemented goes to pot. example file ...

Regular Expression for splitting string

I am looking for regular expression to get the match as "HELLO" and "WORLD" separately when the input is any of the following: "HELLO", "WORLD" "HELL"O"", WORLD" "HELL,O","WORLD" I have tried few combination but none of them seem to work for all the scenarios. I am looking to have my c# code perform something like this: string patte...

Simple regex match question

Hi! I have the following string "sometextsometextSiteId-111-aaaaasometext" If the string contains "SiteId-111-aaaaa" I would like to get the 111-aaaaa part. (any number, any char) "sometextsometextSiteId-111-aaaaasometext" -> 111-aaaaa "sometextsometextSiteId-123-abcdesometext" -> 123-abcde "sometextsometextsitId-111-aaaaasometext" ...

Regular expression of host address?

I want a regular expression for javascript to validate host address like http://192.168.10.10:8089/ and www.abc.com and www.abc.com.aa ...

Regex expression for valid website link

Hi, In my asp.net application, i need to validate the text for a valid website link. I want to use the regular expression validator for that. Anyone with any idea of how to validate the weblink user regex. ...

0.01 to 99.99 in a regular expression

I'm trying to do a regular expression that'll allow numbers from 0.01 to 99.99, but not 0.0 or any null value (00.00 or 00.0 or 0.00 or 0.0) or negative value either. I've come quite close, but as usual something just isn't right. 0.0 shows as valid. Can you please help me fix this. Also, you don't need to keep the expression I've done :...

Is it possible to convert an array of strings into one string?

In my program, I read in a file using this statement: string[] allLines = File.ReadAllLines(dataFile); But I want to apply a Regex to the file as a whole (an example file is shown at the bottom) so I can eliminate certain stuff I'm not concerned with in the file. I can't use ReadAllText as I need to read it line by line for anothe...