regex

How to use regular expressions to pull a substring? (screen scraping)

Hey guys, i'm really trying to understand regular expressions while scraping a site, i've been using it in my code enough to pull the following, but am stuck here. I need to quickly grab this: http://www.example.com/online/store/TitleDetail?detail&amp;sku=123456789 from this: ('<a href="javascript:if(handleDoubleClick(this.id)){windo...

.NET regex inner text between td, span, a tag

<table > <tr> <td colspan="2" style="height: 14px"> tdtext1 <a>hyperlinktext1<a/> </td> </tr> <tr> <td> tdtext2 </td> <td> <span>spantext1</span> </td> </tr> </table> This is my sample text how to write a regular expressi...

PHP regex to search across multiple lines

I'm using preg_* in PHP to search for the pattern <!-- %{data=THIS GETS MATCHED}% --> and pull out the matched text. The pattern for this is: preg_match('#<!-- %{' . $knownString . '\s*=\s*(.*?)}% -->#', ...) What I would like it to do is search across multiple lines for the string. For example: <!-- %{data= THIS GETS MATCHED AND RE...

Regex | validation error

I'm trying to validate a USA mobile number, since I'm using pre-built javascript validation library I just replaced this regex validation with the previous one which comes with the validation library. previous validation regex: "telephone":{ "regex":"/^[0-9\-\(\)\ ]{10,10}$/", "alertText":"* Invalid phone number"}, This works like 21...

Regular Expression to match a string

Hi, I've got two possible string inputs that my application will receive, and if it matches the following two strings, I need it regex.ismatch() to return true: "User * has logged out" "User * has joined" I'm not that good at regex and just can't figure out how to go about matching the above. Any help would be great!!! ...

How do we match any single character including line feed in Perl regular expression?

I would like to use UltraEdit regular expression (perl) to replace the following text with some other text in a bunch of html files: <style type="text/css"> #some-id{} .some-class{} //many other css styles follow </style> I tried to use <style type="text/css">.*</style> but of course it wouldn't match anything because the dot matc...

Regex remove everything thats outside { }

Regex to remove everything outside the { } for example: before: |loader|1|2|3|4|5|6|7|8|9|{"data" : "some data" } after: {"data" : "some data" } with @Marcelo's regex this works but not if there are others {} inside the {} like here: "|loader|1|2|3|4|5|6|7|8|9| {'data': [ {'data':'some data'} ], }"...

RegEx, select anything thats not in brackets...

In RegEx, how would I select anything thats not in brackets: E.g. Xxxxxxx (01010101) would return Xxxxxxx ? Thanks! ...

Extract and use a part of string with a regex in GVIM

I've got a string: doCall(valA, val.valB); Using a regex in GVIM I would like to change this to: valA = doCall(valA, val.valB); How would I go about doing this? I use %s for basic regex search and replace in GVIM, but this a bit different from my normal usages. Thanks ...

How extract part of an URL in PHP?

So, I have this url in a string: http://www.domain.com/something/interesting_part/?somevars&amp;othervars in PHP, how I can get rid of all but "interesting_part"? ...

Simple C# Tokenizer Using Regex

I'm looking to tokenize really simple strings,but struggling to get the right Regex. The strings might look like this: string1 = "{[Surname]}, some text... {[FirstName]}" string2 = "{Item}foo.{Item2}bar" And I want to extract the tokens in the curly braces (so string1 gets "{[Surname]}","{[FirstName]}" and string2 gets "{Item}" and ...

How to replace string of digits with a padded version of that string in regular expression substitution?

I've got a string of digits that is either 4 or 5 digits long and it needs to be padded with "0" till it's 6 digits long. Is this possible? I'm using .Net framework. ...

How to let regex know that it should stop after a first occurence?

string time = "Job started: donderdag 6 mei 2010 at 20:00:02" var filterReg = new Regex(@".*:", RegexOptions.Compiled); time = filterReg.Replace(time, String.Empty); Is it possible to stop after the first occurence? so at the first ":". ...

What's wrong with this regex (VBScript/Javascript flavor)

I'm trying to run a regular expression in VBA code that uses Microsoft VBScript Regular Expressions 5.5 (should be the same as JavaScript regex) regex: ^[0-9A-Z]?[0-9A-Z]{3}[A-Z]?([0-9A-Z]{6})-?([0-9])?$ input: X123A1234567 match: 123456 The six characters I'm interested in give a good match of 123456, ignoring the last (check) digit. ...

Retain Delimiters when Splitting String

Edit: OK, I can't read, thanks to Col. Shrapnel for the help. If anyone comes here looking for the same thing to be answered... print_r(preg_split('/([\!|\?|\.|\!\?])/', $string, null, PREG_SPLIT_DELIM_CAPTURE)); Is there any way to split a string on a set of delimiters, and retain the position and character(s) of the delimiter after th...

How can I match end-of-line multiple times in a regex without interpolation?

Hi, if I have a input with new lines in it like: [INFO] xyz [INFO] How can I pull out the xyz part using $ anchors? I tried a pattern like /^\[INFO\]$(.*?)$\[INFO\]/ms, but perl gives me: Use of uninitialized value $\ in regexp compilation at scripts\t.pl line 6. Is there a way to shut off interpolation so the anchors work as expe...

How do I find if string has at least one character using regex?

Examples: "1 name": Should say it has characters "10,000": OK "na123me": Should say it has characters "na 123, 000": Should say it has characters ...

Is is possible to parse a web page from the client side for a large number of words and if so, how?

I have a list of keywords, about 25,000 of them. I would like people who add a certain < script> tag on their web page to have these keywords transformed into links. What would be the best way to go and achieve this? I have tried the simple javascript approach (an array with lots of elements and regexping/replacing each) and it obviousl...

Regular expression for validating month

What is the regular expression for validating a month with the leading zero? Passes regular expression: 01,02,03,04,05,06,07,08,09,10,11,12 Fails regular expression: 1, 00, 13 and up. ...

Delete the last instance of a certain string from a text file without changing the other instances of the string

Hello, I have a C# program where I am using a lot of RegEx.Replace to replace text in my text file. Here is my problem. In my text file, I have a code such as "M6T1". This code is listed in numerous places in the text file. However, I only want to delete it from the bottom (last instance) in the text file. There will always be a "M...