regex

Make groups with regular expresion like in perl?

In Perl if I use this regex /(\w+)\.(\w+)/ on the string "1A3.25D", the global vars $1 strores "1A3" and $2 stores "25D". Is there a way to do this in C#? ...

How to clean up a string to use as a filename in PERL?

I have a job application form where people fill in their name and contact info and attach a resume. The the contact info gets emailed and the resume attached. I would like to change the name of the file to that it is a combination of the competition number and their name. How can I clean up my generated filename so that I can guarante...

emacs regexp-builder doesn't work in replace-regexp

Hi I have an emacs buffer containing the text a1b2c3 using the regexp-builder, i create the regexp "b\\(2\\)" and can see the match highlighting (b2, with the 2 in a different colour). however, when i paste the expression into replace-regexp, i get 0 matches. both with and without the quotes. to get a match i need to use b\(2\)...

Performance of character classes vs "shorthand" classes

While answering another question, it was brought up that there might a difference, performance-wise, between an explicit character class ([0-9]) and a "shorthand" class (\d). My initial reaction was that if a difference exists at all, it'd be negligible, but I don't have (and couldn't find) any info about it or figure out how I could tes...

Using capture buffers in a Perl regular expression stored in a variable.

I am receiving the left and right sides of a regular expression replacement as the arguments to a function. I want my users to be able to use capture buffers, but it doesn't work the way I'm trying to do it. my $string = "This is my string"; $string = regex_replace($string,'is (my) string','$1'); print "$string\n"; sub regex_replace...

Java Regular Expression

{ Main Block { Nested Block } } { Main Block { Nested Block } { Nested Block } } I want to get data within Main Blocks including its Nested Blocks with Java Regex. Is it possible? Thanks in Advance ...

How to find hard erroneous interface casts in Delphi (Win32)

I am trying to find some mysterious bugs in an application, and believe the cause may be some hard casts on interfaces. Such casts are unsafe in Delphi, for example ISomeInterface(CurrentObj) which should be CurrentObj as ISomeInterface In light of the lack of compiler warnings which in my opinion should be emitted for hard cast...

RegExp get string inside string

Let presume we have something like this: <div1> <h1>text1</h1> <h1>text2</h1> </div1> <div2> <h1>text3</h1> </div2> Using RegExp we need to get text1 and text2 but not text3. How to do this? Thanks in advance. EDIT: This is just an example. The text I'm parsing could be just plain text. The main thing I want to accompli...

PHP regular expression to match price or amount

I need a regex that will match on a price or amount. It should match on these 100 410.00 0.12 but not these 100.000 -600.00 .12 .1234 This works for all of the above cases except for single values like 1 /^[0-9]*\.?[0-9]{2}+$/ How can I adjust it so single integers will match? And can anyone explain why the current one is wr...

Why regular expression in Java cannot recognize \s as space character ?

I read from a lot of webpage (for example: http://www.wellho.net/regex/java.html), they all mentioned that \s could represent any space charactor. But when I use \s in Java, it is not an eligible expression. Anyone know the reason? ...

Another way instead of escaping regex patterns?

Usually when my regex patterns look like this: http://www.microsoft.com/ Then i have to escape it like this: string.match(/http:\/\/www\.microsoft\.com\//) Is there another way instead of escaping it like that? I want to be able to just use it like this http://www.microsoft.com, cause I don't want to escape all the special charact...

Regular expression for matching latitude/longitude coordinates?

I'm trying to create a regular expression for matching latitude/longitude coordinates. For matching a double-precision number I've used (\-?\d+(\.\d+)?), and tried to combine that into a single expression: ^(\-?\d+(\.\d+)?),\w*(\-?\d+(\.\d+)?)$ I expected this to match a double, a comma, perhaps some space, and another double, but it ...

IIS7 URL Rewrite - RegExp to match any string that does not contain a DOT (.)

I am using URL Rewrite module 2 in IIS 7. I have a certain rule for rewriting URLs in IIS. But I want that rule to apply to only strings that DO NOT contain a DOT (.) If the string contains a DOT, I want it to fail and simply be not rewritten. I thought this will work - ^([^.]+) but it rejects only strings that start with a DOT. Examp...

Scrape unique image URLs from HTML

Using PHP to curl a web page (some URL entered by user, let's assume it's valid). Example: http://www.youtube.com/watch?v=Hovbx6rvBaA I need to parse the HTML and extract all de-duplicated URL's that seem like an image. Not just the ones in img src="" but any URL ending in jpe?g|bmp|gif|png, etc. on that page. (In other words, I don't ...

python string conversion for eval.

I have list like: ['name','country_id', 'price','rate','discount', 'qty'] and a string expression like exp = 'qty * price - discount + 100' I want to convert this expression into exp = 'obj.qty * obj.price - obj.discount + 100' as I wanna eval this expression like eval(exp or False, dict(obj=my_obj)) my question is what would b...

Get source of image

I have a next string like: <img src="../uplolad/commission/ranks/avatar.jpg' . $row[$c_name] .'" width="50" height="50"/> How can i get a image file name in javascript? I know only PHP regexes. Extention of a file can be different. The result must be: avatar.jpg ...

Python Regex, re.sub, replacing multiple parts of pattern?

I can't seem to find a good resource on this.. I am trying to do a simple re.place I want to replace the part where its (.*?), but can't figure out the syntax on how to do this.. I know how to do it in PHP, so I've been messing around with what I think it could be based on that (which is why it has the $1 but I know that isn't correct i...

Can I shorten this regular expression?

I have the need to check whether strings adhere to a particular ID format. The format of the ID is as follows: aBcDe-fghIj-KLmno-pQRsT-uVWxy A sequence of five blocks of five letters upper case or lower case, separated by one dash. I have the following regular expression that works: string idFormat = "[a-zA-Z]{5}[-]{1}[a-zA-Z]{5}[-]...

Find the indexes of all regex matches in Python?

Hi everyone, I'm parsing strings that could have any number of quoted strings inside them (I'm parsing code, and trying to avoid PLY). I want to find out if a substring is quoted, and I have the substrings index. My initial thought was to use re to find all the matches and then figure out the range of indexes they represent. It seems...

The point of PHP's recent dropping of [[:POSIX:]] regular expression flavor

Dropping of the ereg-functions and their POSIX-regular expression flavor in later PHP versions? After reading an older posting concerned of this - and reading the official PHP statement I'm inclined to ask what this is about. Following the development of PHP over the years (and doing much development in Perl and PHP) I'm really unsure i...