regex

How can I ignore case in a regex?

I have an ASP.NET RegularExpressionValidator that checks file extensions. Is there a quick way I can tell it to ignore the case of the extension without having to explicitly add the upper case variants to my validation expression? ValidationExpression="([^.]+[.](jpg|jpeg|gif|png|wpf|doc|docx|xls|xlsx ... ...

Python-Regex, what's going on here?

I've got a book on python recently and it's got a chapter on Regex, there's a section of code which I can't really understand. Can someone explain exactly what's going on here (this section is on Regex groups)? >>> my_regex = r'(?P<zip>Zip:\s*\d\d\d\d\d)\s*(State:\s*\w\w)' >>> addrs = "Zip: 10010 State: NY" >>> y = re.search(my_regex, a...

.Net C# regex for parsing URL parameters

I need to parse a string, such as /a/b/c/d=uno/c=duo.html into three groups, such as /a/b/c/ d=uno/ c=duo.html The parsing rules are: The first group is everything until "d=" or the whole string if "d=" is not a part of the string. The second group is everything until "c=" or the rest of the string following the first group if "c=...

Getting the content of XHTML tags: p, ul and/or ol from string

Hi I have a CMS with a WYSIWYG editor which produces pretty good xhtml. Based on this fact, I think a HTML parser might be slightly overkill for this small job. I am intending to use regular expressions but so far have been unable to get mine to match what I'm after. I'm using PHP5. I need to match the content of the 3 block level el...

Python Split String

Lets Say we have Zaptoit:685158:[email protected] How do you split so it only be left 685158:[email protected] ...

matching a line that doesn't contain specific text with regular expressions

I want to do the following with regular expressions but not sure how to do it. I want it to match "one two" when one two is the beginning of the line unless the string contains "three" anywhere after "one two". Note the " marks are just to represent string literals I don't need to match on them. ...

DFA -> regular expression

Hi, I've written a DFA on paper, and want to translate it into a set of regular expressions. Does anybody know a good tool to do this? ...

i want to find all if statements in C# code which are not followed by brackets. Through regex

I want to find all if statements and for statements which are not followed by curly brackets '{'. When you write a single line in an if statement you do not mostly enclose it in curly brackets, so I want to find all those if and for statements. Please help! Like I want to capture this statement if (childNode.Name == "B") return To...

Greasemonkey: Text processing - What's the best way to find certain words in a website and have a function work on it?

I want greasemonkey to scan through a website and change certain words to something else. Is there a way to do it with regex or some other string processing function in javascript? Thanks for your help :) ...

Regular Expression to match {if cond}foo{else}bar{/if}

Hi, I'm having difficulty throwing away the bits of the expression I don't want, and keeping the bits I do. The problem is - given the input string: {if cond}foo{else}bar{/if} I'd like just to have: 0: {if cond}foo{else}bar{/if} 1: cond 2: foo 3: bar And for the input string: {if cond}foo{/if} I'd like just to have: 0: {if co...

Vim Case-Agnostic Regex

I've run into the following case a few times and I was wondering if there is a fast way to handle it in Vim. I'll have a source file like the following: #ifndef _FOO_H_ #define _FOO_H_ class Foo { Foo(int foo); }; #endif And I would like to convert it to the following: #ifndef _BAR_H_ #define _BAR_H_ class Bar { Bar(int ba...

Regular expression to find and replace the content of HTML Comment Tags

I have a CMS that uses a syntax based on HTML comments to let the user insert flash video players, slideshows, and other 'hard' code that the user could not easily write. The syntax for one FLV movies looks like this: <!--PLAYER=filename.flv--> I use this code: $find_players = preg_match("/<!--PLAYER\=(.*)-->/si", $html_content, $mat...

Do you know a good REGEX lib for C Language?

Hi all, I've found two libs to work with Regular Expression in Ansi C: [Lightweight C++] http://students.ceid.upatras.gr/~sxanth/lwc/ This is not really a Regexp lib but I can use it to write my expressions on it and then execute the preprocessor to get the generated C code. [Real Regex Lib] http://www.osix.net/modules/article/?id=349...

Regex for url validation with parts capturing

Can a single regex be used to valdate urls and match all the parts, I have been working on one and what I have come up with so far is: (?:(?P<scheme>[a-z]*?)://)?(?:(?P<username>.*?):?(?P<password>.*?)?@)?(?P<hostname>.*?)/(?:(?:(?P<path>.*?)\?)?(?P<file>.*?\.[a-z]{1,6})?(?:(?:(?P<query>.*?)#?)?(?P<fragment>.*?)?)?)? however this does...

Regular expression to remove hostname and port from URL?

I need to write some javascript to strip the hostname:port part from a url, meaning I want to extract the path part only. i.e. I want to write a function getPath(url) such that getPath("http://host:8081/path/to/something") returns "/path/to/something" Can this be done using regular expressions? ...

C# Replace with Callback Function like in AS3

In AS3 you have a function on a string with this signature: function replace(pattern:*, repl:Object):String The repl:Object can also specify a function. If you specify a function, the string returned by the function is inserted in place of the matching content. Also, is it possible to get the the original string in which I want to re...

How can I extract external referrers from an Apache access log with Perl?

I need some help getting a regex working to parse all referrers from an apache access log file which come from real links offsite and which are valid referrals from real people rather than bots or spiders. I'm working in Perl. This bit of code almost works already [the access log is opened with the filehandle $fh]: my $totalreferals = ...

Regex to match all valid links

In regards to this: http://stackoverflow.uservoice.com/pages/general/suggestions/103227-parser-does-not-match-all-valid-urls is this regex adequate or will it need to be refined, if it needs to be refined how so? \b(?P<link>(?:.*?://)[\w\-\_\.\@\:\/\?\#\=]*)\b ...

How to use regex to get part of string in c#

I am try use (?<key>.{5}keyword.{5}?) to test "other string keyword other text" it will get "ring keyword othe" and I want "akeyword other text" or "other string keyworda" or "akeywordc" are match, too. How to modify regex? I have a long string and I want get find keyword and get it with perfix and suffix string demands 5 just...

vim regular expression

I have following text in a file 23456789 When i tried to replace the above text using command 1,$s/\(\d\)\(\d\d\d\)\(\d\d\)*\>/\3\g I am getting 89. Should't it be 6789? Can anyone tell me why it is 89. ...