regex

"Lenient" regex matching of similar characters in C#/.Net

Is there a way to get .Net to positively match strings, even if some characters are not exactly the same? Examples of characters that should be considered to be similar could be: 'a'/'á' and 'í'/'i'. The Chrome browser find-as-you-type recognizes these characters as being equivalent. ...

Regex fails with whitespace

$match = array('~(?:face\=[\'"]?(\w+)[\'"]?)~i', '~~i'); $replace = array('font-family:$1;', '<span style="$1">'); I want to replace the old <font> element which has a "face" attribute with a new <span> element with "style" attribute but the regex always fail when the font name in the "face" attribute contains whitespace, e.g : Co...

Regular expression help in PHP

I need extract data from a string. Heres an example: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; tr-tr) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3 I want to get what's after the "Safari/" (417.9.3) but: The "Safari" string can be in any character case and can be anywhaere in the string. The version is separated from "Saf...

Where is this newline coming from?

I'm using a rake script to tag the AssemblyInfo.cs files in my .NET projects, but there's a phantom carriage return (or newline, etc.) being introduced that's breaking the compilation. The method that gets the version number is: def get_version() version = '' IO.popen("#{SVNVERSION_APPLICATION} #{build_info.root_dir}") do |output| ...

javascript \d regular expression unexpected behavior

I am trying use javascript regular expressions to do some matching and I found a really unusual behavior that I was hoping someone could explain. The string I was trying to match was: " 0 (IR) " and the code block was finalRegEx = new RegExp("[0-9]"); match = finalRegEx.exec(str); except that when I put "\d" instead of "[0-9]" it...

Python parsing files

I need to know the best approach for the following scenario lets say we have some huge file which logs the output of the compilation and there are couple of error patterns which I want to test against this file, for eg. error patterns could be - : error: - : error [A-Z]*[\d ]* - [A-Z]*[\d]* [E\e|rror: - " Cannot open include file ...

Union in regular expression in R

I'm trying to use regular expressions in R to find one or more phrases within a vector of long sentences (which I'll call x). So, for example, this works fine for one phrase: grep("(phrase 1)",x) But this doesn't work for two (or more) phrases: grep("(phrase 1)+(phrase 2)+",x) As I would expect. As I read it, this last one should ...

regular expression: a pattern either before or after a symbol

I need find a line matching a pattern like: A xx B xx, where xx is a pattern that is either before or after B. ...

Splitting YYYYMMDD date into 3 parts in Perl

How do I split a date that is of the form YYYYMMDD into its constituents? my ($yyyy, $mm, $dd) = $date =~ /(\4d+)(\2d+)(\2d+)/; ...

regular expression: Efficiency of case insensitive comparsion

Given a pattern p and a string s, suppose p is in lower case. Which of the following two is more efficient? r = re.compile(r'p', RE.IGNORECASE) r.match(s) ... or ... r = re.compile(r'p') r.match(s.lower()) ...

Make codeigniter behave on $_GET's ?

I've had a problem with CI handling $_GET and found a way to overcome it. The question is, can you see any security problem here? I have my urls all ways like /contacts /company/info And my default controller on CodeIgniter is called index I can make CI behave with $_GET as long as I follow the class/function/default_controller....

Use Regex to replace HREFs

I have html email that I would like to track click activity. I need to update all hrefs within the email to point back to my server where they can be logged and redirected. Is there an easy way to do this globally using .Net regex? <a href="http://abc.com"&gt;ABC&lt;/a&gt; becomes <a href="http://mydomain.com?uid=123&amp;url=http:/ab...

Regex to read a class file

Hi I am looking for a Regex to read a c# class file like MyClass{} The regex shld return "MyClass" when passed the string "MyClass{}". Edited: Common { MyClass1 { Method1 { "Helloworld"; "GoodBye"; } Method2 { "SayGoodMorning"; } } MyClass2 { Method3 { "M3"; ...

Find a string and replace it more effeciently

Situation: I have a html file and I need to remove certain sections. For Example: The file contains html: <div style="padding:10px;">First Name:</div><div style="padding:10px; background-color: gray">random information here</div><div style="padding:10px;">First Name:</div><div style="padding:10px; background-color: gray">random infor...

Regex fails to match for no obvious reason.

Consider the two following regular expression snippets and dummy HTML that it should be matching: Apparently, I can only post one link until I get more reputation, so the link below contains the three links I referenced above: http://pastebin.com/Qj1uxfdk The difference between the two snippets, if anyone is wondering, is a removed ((...

Regex: 5 digits in increasing order

i need regex for 5 digits in increasing order, like 12345, 24579, 34680, and so on. 0 comes after 9. ...

Is there a bundled library for regular expressions in MSVC?

If I'm compiling a C program with gcc, I can safely assume that the functions in regex.h are available. Is there a regex library I can assume is there if someone is compiling with microsoft's C compiler? ...

Regex: Repeated capturing groups

I have to parse some tables from an ASCII text file. Here's a partial sample: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212 RECKITTBEN 192.50 209.00 192.50 201.80 5.21 34 2850 5.707 RUPALIINS 150.00 159.00 150.00 156.25 6.29 4 80 .125 SALAMCRST 164.00 164...

Javascript RegEx Help

I admit, after all these years I suck at regex. I am hoping someone and quickly help me with this. var str = "11 FT 0 IN | 10' ( +$2,667.00 )"; var match = str.match(/**no clue what to do**/g); // results needed match[0] = "11 FT 0 IN"; match[1] = "10'"; match[2] = "( +$2,667.00 )"; ...

PHP conditional string replacement

I'm trying to replace the ~ into | between the [ ] in the folowwing case: {stackoverflow is a [cool~great~fast] website ~ Find your answers [easily~quickly] on stackoverflow}. Note: The text between the [ ] can be multiline. I've tried multiple regexs buth with no luck. My closest call at the moment is: $text = preg_replace("/\[(.*...