regex

How can I make this regex match correctly?

Given this regex: ^((https?|ftp):(\/{2}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)*?))(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum){1}) Reformatted for readability: @"^((https?|ftp):(\/{2}))?" + // http://, https://, ftp:// - Protocol Option...

Matching regular expressions against non-Strings in Ruby without conversion

If a Ruby regular expression is matching against something that isn't a String, the to_str method is called on that object to get an actual String to match against. I want to avoid this behavior; I'd like to match regular expressions against objects that aren't Strings, but can be logically thought of as randomly accessible sequences of ...

Bug in a PHP regex

I am trying to print "1" if there are at least two of the same figure in the match, else 0. What is wrong in the regex? if ( max ( array_map ('strlen', preg_split('/([0-9])[^0-9]*\1/', "1 2 3 1 4") ) ) == 1 ) echo 1; else echo 0; ...

.NET regular expression find the number and group the number

I have a question about .NET regular expressions. Now I have several strings in a list, there may be a number in the string, and the rest part of string is same, just like string[] strings = {"var1", "var2", "var3", "array[0]", "array[1]", "array[2]"} I want the result is {"var$i" , "array[$i]"}, and I have a record of the number whi...

How do I write a Perl script to filter out digital pictures that have been doctored?

Last night before going to bed, I browsed through the Scalar Data section of Learning Perl again and came across the following sentence: the ability to have any character in a string means you can create, scan, and manipulate raw binary data as strings. An idea immediately hit me that I could actually let Perl scan the pictures tha...

Can I turn on extended regular expressions support in Vim?

The characters for extended regular expressions are invaluable; is there a way to turn them on so that I don't have to escape them in my Vim regex, much like the -E flag I can pass to grep(1)? ...

how to find a number in a string using javascript.

Suppose i have a string like - "you can enter maximum 500 choices". So extract 500 from the string. The main problem is the String may vary like "you can enter maximum 12500 choices". So how to get the integer part. ...

.NET Regex, only numeric, no spaces

I'm looking for a regular expression that accepts only numerical values and no spaces. I'm currently using: ^(0|[1-9][0-9]*)$ which works fine, but it accepts values that consist ONLY of spaces. What is wrong with it? ...

std::regex -- is there some lib that needs to be linked?

I get a linker error with the following code: #include <regex> int main() { std::regex rgx("ello"); return 0; } test.o: In function `basic_regex': /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/tr1_impl/regex:769: undefined reference to `std::basic_regex<char, std::regex_traits<char> >::_M_compile()' collec...

Regular expression (alphanumeric)

I need a regular expression to allow the user to enter an alphanumeric string that starts with a letter (not a digit). ...

How to put multiple conditions in one regular expression?

Hi, I want to write a regular expression for the following scenario. If line starts with word "project", then allow any type of character after it except "." (dot). For example: project is to pick up of discontinued items. The above line should not get selected and the following lines should get selected: project : Project...

Python - RegExp - Modify text files

Hi All, Newbie to Python.... help requested with the following task :-) I have tree of various files, some of them are C source code. I would like to modify these C files with python script. The C code has 4 defines - #define ZR_LOG0(Id, Class, Seveity, Format) #define ZR_LOG1(Id, Class, Seveity, Format, Attr0) #define ZR_LOG2(Id, Cl...

Regular expression to Extract substring

Hi I have a string like below url('/testProject/Images/Current/Universal/Styles/MasterPage_HomeIcon.gif') repeat-x How can I extract the substring starting from ' to end ' ? I am using language as C# ...

C# superfast "mailmerge" type replace

I hoping for some pointers on the quickest way to do a replace when the document that needs bits replacing is constant (a sort of mailmerge scenario). Of course there are lots of ways of doing replaces using string.replace and regexp but it looks like they need to parse the input document each time looking for the match. That's the bit ...

How to use lookbehind or lookahead and replace the matched string?

Hi, I am stuck at one more RegEx. Sample input : project description I want to write RegEx. that if word "description" is found and its preceded by word "project" then prepend "project description" with "<project>". expected output : <project>project description I wrote following Regex, n replacement string but its not working :...

java: search & replace in a Stream

How do I do on-the-fly search & replace in a Java Stream (input or output)? I don't want to load the stream into memory or to a file. I just see the bytes passing by and I need to do some replacements. The sequences being replaced are short (up to 20 bytes). ...

JavaScript: string.match regular expression help

Hello gurus, I have a javascript function that looks element id with certain patterns. So I have the following script: if (f.elements[i].id.match(/DataList\[-\d{3}|\d{3}\]\.MemberId/)) { //do something } It should match elements with ids such as these: DataList[-1].MemberId DataList[-2].MemberId And it does, however it also matc...

Is there a regular expression dll or library that I can use for a language that does not have one?

Hi, I program in Visual DataFlex. Are there any libraries that I can use to give my programs regular expression matching? It could be ActiveX, or COM, or maybe even just a DLL. ...

MySQL - REGEXP in a WHERE statement?

I have a table with a field called 'user_car'. It consists of a cat'd underscore separated value (user's id _ car's id) user_car rating ----------------------------- 11_56748 4 13_23939 2 1_56748 1 2001_56748 5 163_23939 1 I need to get the average rating for any "car". In my ex...

Email body regex search

Here is an example email body: Name: Jah Selassie Store Locator: Finland Service Number: alphanumeric I am looking for a regex to search through the body of an email and check for a location entry after "Store Locator". ...