regex

How do I match any character across multiple lines in a regular expression?

For example, this regex (.*)<FooBar> will match: abcde<FooBar> But how do I get it to match across multiple lines? abcde fghij<FooBar> ...

What is the best regular expression to check if a string is a valid URL

I need to check if a given string is a valid URL address. My knowledge of regular expressions is basic and doesn't allow me to choose from the hundreds of regex i've already seen on the web. ...

VERY slow running regular expression when using large documents

Thanks in advance for your consideration I need to convert inline css style attributes to their HTML tag equivelants. The solution I have works but runs VERY slowly using the Microsoft .Net Regex namespace and long documents (~40 pages of html). I've tried several variations but with no useful results. I've done a little wrapping aro...

Regular expresion to match urls JAVA

I use RegexBuddy while working with regular expressions. From its library i copied the regular expression to match urls. I tested succesfully within regexbuddy. However, when I copied it as Javas String flavor and pasted it into java code it does not work. The next class prints false: public class RegexFoo { public static void mai...

How to "inverse match" with regex?

I'm using RegexBuddy but I'm in trouble anyway with this thing :\ I'm processing line by line a file. I built a "line model" to match what I want. Now i'd like to do an inverse match... i.e. I want to match lines where there is a string of 6 letters, but only if these six letters are not Andrea, how should I do that? EDIT: I'll writ...

UK Postcode Regex (Comprehensive)

I'm after a regex that will validate a full complex UK postcode only within an input string. All of the uncommon postcode forms must be covered as well as the usual. For instance: Matches CW3 9SS SE5 0EG SE50EG se5 0eg WC2H 7LT No Match aWC2H 7LT WC2H 7LTa WC2H Are there any official or even semi-official regexes in use for this...

Why is my Perl regex using so much memory?

I'm running a regular expression against a large scalar. Though this match isn't capturing anything, my process grows by 30M after this match: # A if (${$c} =~ m/\G<<\s*/cgs) { #B ... } $c is a reference to a pretty big scalar (around 21M), but I've verified that pos(${$c}) is in the right place and the expression matches at ...

Need a regular expression to match three character strings

I generally stay away from regular expressions because I seldom find a good use for them. But in this case, I don't think I have choice. I need a regex for the following situation. I will be looking at three character strings. It will be a match if the first character is 1-9 or the letters o,n,d (lower or upper) AND the second chara...

What is best way to remove duplicate lines matching regex from string using Python?

This is a pretty straight forward attempt. I haven't been using python for too long. Seems to work but I am sure I have much to learn. Someone let me know if I am way off here. Needs to find patterns, write the first line which matches, and then add a summary message for remaining consecutive lines which match pattern and return modified...

Regular expression for parsing name value pairs

Can someone provide a regular expression for parsing name/value pairs from a string? The pairs are separated by commas, and the value can optionally be enclosed in quotes. For example: AssemblyName=foo.dll,ClassName="SomeClass",Parameters="Some,Parameters" ...

A Question of Greedy vs. Negated Character Classes in Regex

I have a very large file that looks like this (see below). I have two basic choices of regex to use on it (I know there may be others but I'm really trying to compare Greedy and Negated Char Class) methods. ftp: [^\D]{1,} ftp: (\d)+ ftp: \d+ Note: what if I took off the parense around the \d? Now + is greedy which forces backtrackin...

Escaping a String from getting regex parsed in Java

In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so: if (T.matches(S)) ... (note: the above line was T.contains() until a few posts pointed out that that method does not use regexes. My bad.) But now suppose S may have unsavory characters in it. For instance, let S = "[hi"...

Yahoo Username Regex

I need a (php) regex to match Yahoo's username rules: Use 4 to 32 characters and start with a letter. You may use letters, numbers, underscores, and one dot (.). ...

Regex for parsing directory and filename

I'm trying to write a regex that will parse out the directory and filename of a fully qualified path using matching groups. so... /var/log/xyz/10032008.log would recognize group 1 to be "/var/log/xyz" and group 2 to be "10032008.log" Seems simple but I can't get the matching groups to work for the life of me. NOTE: As pointed out b...

Regex to check if valid URL that ends in .jpg, .png, or .gif

I would like users to submit a URL that is valid but also is an image, ending with .jpg, .png, or .gif. ...

RegEx: Grabbing values between quotation marks

I have a value like this "Foo Bar" "Another Value" something else What RegEx expression will return the values enclosed in the quotation marks (e.g. Foo Bar and Another Value)? ...

Is there a regular expression to detect a valid regular expression?

Is is possible to detect a valid regular expression with another regular expression? If so please give example code below. ...

How can I check if at least one of two subexpressions in a regular expression match?

I am trying to match floating-point decimal numbers with a regular expression. There may or may not be a number before the decimal, and the decimal may or may not be present, and if it is present it may or may not have digits after it. (For this application, a leading +/- or a trailing "E123" is not allowed). I have written this regex...

Regular Expression: Match to (aa|bb) (cc)?

My regular expression needs to be able to find the strings: Visual Studio 2008 Visual Studio Express 2008 Visual Basic 2008 Visual Basic Express 2008 Visual C++ 2008 Visual C++ Express 2008 and a host of other similar variants, to be replaced with this one single string Visual Studio 2005 I tried "Visual (Basic|C++|Studio) (Exp...

Regex to match url end-of-line or "/" character

I have a url and I'm trying to match it to a regular expression to pull out some groups. The problem I'm having is that the url can either end or continue with a "/" and more url text. I'd like to match urls like this: http://server/xyz/2008-10-08-4 http://server/xyz/2008-10-08-4/ http://server/xyz/2008-10-08-4/123/more But not mat...