regex

How do I make a regex match for measurement units?

I'm building a small Java library which has to match units in strings. For example, if I have "300000000 m/s^2", I want it to match against "m" and "s^2". So far, I have tried most imaginable (by me) configurations resembling (I hope it's a good start) "[[a-zA-Z]+[\\^[\\-]?[0-9]+]?]+" To clarify, I need something that will match lett...

Regular expresion for urlpattern

I need a regexp for a URL like: /slug/#slug/slug/ I know it should be something like: r'^(?P<slug1>[-\w]+)/#(?P<slug2>[-\w]+)/(?P<slug3>[-\w]+)/$' But I am having problems with the character # ...

Regular expression to match text between <a ..> and </a>

Could anyone be able to give a regular expressiont to match the link text between <a> and </a> tags in a HTML snippet. Sample data: <a href="link.html">Link Title</a> - 15 comments <br/> <a href="otherlink.html">Some other Title</a> - 6 comments Requirement: I need to extract only the link texts (i.e. the one between <a> and </a> - Lin...

Match first word of a phrase in a String.

I am using the GTMRegex class from the Google toolbox for mac (in a Cocoa / Objective-C) app: http://code.google.com/p/google-toolbox-for-mac/ I need to do a match and replace of a 3 word phrase in a string. I know the 2nd and 3rd words of the phrase, but the first word is unknown. So, if I had: lorem BIFF BAM BOO ipsem and lorem B...

HtmlAgilityPack expression to get this?

Hi I am going through a html string with HtmlAgilityPack. Now what I need to get everything between a tagg. It looks like this. <left> <table>..</table> <table>..</table> <table>..</table> <table>..</table> <table>..</table> </left> Now I use this expression for this task. EDIT: var htmlResult = doc.DocumentNode.Selec...

Python RegEx Discrepancy vs Kodos and RegExr: Can't Filter Specific Character in Python

Hi, I'm using Python 2.6.3. When I do: import re, urllib f = urllib.urlopen(website) z = f.read() a = re.findall(r'(\b\d*\SLegos\b)[^\\/bLegos\b]', z) print a I get: ['/Legos', '/Legos', '525Legos', '53Legos', '11Legos', '8Legos', '10Legos', '2Legos', '0Legos', '0Legos', '0Legos', '0Legos', '9Legos', '1Legos', '0Legos', '0Legos', '0...

Does any one know how to find following string using regular expression of visual studio?

Does any one know how to find following string using regular expression of visual studio? <fo:block> </fo:block> I have tried with following but it didn't work \<fo\:block\>*$\n*\</fo\:block\>$ ...

Help with an Emacs Regular Expression

Hi SO, I have statements like this all over my code: LogWrite (String1, String2, L"=======format string======", ... ); I want to change each of these to: LogWrite (String1, String2, L"format string", ... ); I'm trying to write the regexp required to do...

multiline matching with ruby

I have a string variable with multiple lines: e.g. "SClone VARPB63A\nSeq_vec SVEC 1 65 pCR2.1-topo\nSequencing_vector \"pCR2.1-topo\"\nSeq_vec SVEC 102 1710 pCR2.1-topo\nClipping QUAL 46 397\n I would want to get both of lines that start with "Seq_vec SVEC" and extract the values of the integer part that matches... string = "Clone V...

Regular expression to strip everything between anchor tags

Hi , I am trying to strip out all the links and text between anchors tags from a html string as below: string LINK_TAG_PATTERN = "/<a\b[^>]*>(.*?)<\\/a>"; htmltext = Regex.Replace(htmltext, LINK_TAG_PATTERN, string.Empty); This is not working anyone have ideas why? Thanks a lot, Edit: the regex was from this link http://stackove...

PHP regex replace white space by &nbsp; if it is following single letter

Hi, I have user defined string (html formated string to be saved and used in web) and need to find a way to replace each white space which is right after a single letter by &nbsp;. For example "this is a string" should become "this is a&nbsp;string", "bla bla b l abla b la blabla" should become "bla bla b&nbsp;l&nbsp;abla b&nbsp;la b...

Regular Expression to List accepted words.

Hi, I need a regular expression to list accepted Version Numbers. ie. Say I wanted to accept "V1.00" and "V1.02". I've tried this "(V1.00)|(V1.01)" which almost works but then if I input "V1.002" (Which is likely due to the weird version numbers I am working with) I still get a match. I need to match the exact strings. Can anyone h...

Python re.sub question

Greetings all, I'm not sure if this is possible but I'd like to use matched groups in a regex substitution to call variables. a = 'foo' b = 'bar' text = 'find a replacement for me [[:a:]] and [[:b:]]' desired_output = 'find a replacement for me foo and bar' re.sub('\[\[:(.+):\]\]',group(1),text) #is not valid re.sub('\[\[:(.+):\]\]'...

Help with regular expressions (Parsing Wikipedia Markup) in PHP

Hi, I have this bit of text that I want to remove from a page I am fetching from Wikipedia. {{Historical populations|type=USA | 1698|4937 | 1712|5840 | 1723|7248 | 1737|10664 | 1746|11717 | 1756|13046 | 1771|21863 | 1790|33131 | 1800|60515 | 1810|96373 | 1820|123706 | 1830|202589 | 1840|312710 | 1850|515547 | 1860|813669 | 1870|942292 ...

PHP: Regular expression problem too much for my small brain

Hi All, I have been trying to solve a PHP regular expression problem for awhile now but I just can't quite get it done. I need write a regex that will match between 7 and 12 digits (0..9) and there may optionally be either a single hyphen or a single space between adjacent digits. This is what I have so far... $match1 = preg_match('/...

RegEx to Tokenize String

I'm trying to create a regex to tokenize a string. An example string would be. John Mary, "Name=blah;Name=blahAgain" "Hand=1,2" I'm trying to get back: John Mary Name=blah;Name=blahAgain Hand=1,2 ...

risky characters to block in asp.net forms?

hi, I'm about to launch a forms auth membership site that will include forms that both international and American users can use to update their profile info and submit requests for info on products (but no actual e-commerce). I'm using asp.net validation controls on the text inputs and I had it pretty tightly filtered for chars using re...

C# regex to match text string

I am trying to use a regex to find text inside a string. For example, have this string: one,two,three,four If I want to see if it has one OR two, I can use "one|two". How do I create a regex for determining whether the string has one AND two? ...

Editing Text in a Nokogiri Element or Using Regex

Is there a way to edit the text of a nokogiri element? I have a nokogiri element that contains a list element (<li>) and I would like to remove some characters from the text while preserving the <li> html. Specifically, I want to remove a leading ":" character in the text if it exists. It doesn't look like there's a text= method for n...

Regex in javascript always matches only 1 character?

It seems like no matter what input I give this, it always only matches 1 character. m.index is always 0 on a match and m.length is always 1. what am I doing wrong here? I have tried it at(and ripped off some code from) http://www.regular-expressions.info/javascriptexample.html and it works as expected there and matches an entire number. ...