regex

How to evaluate an IP?

How can I determine if a string is an IP? Either IPv4 or IPv6? What is the least and most number of characters? I assume this would be a regex answer. ...

Python re.sub MULTILINE caret match

The Python docs say: re.MULTILINE: When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline)... By default, '^' matches only at the beginning of the string... So what's going on when I get the following unexpected result? >>> import re >>...

Regex to match against something that is not a specific substring

I am looking for a regex that will match a string that starts with one substring and does not end with a certain substring. Example: // Updated to be correct, thanks @Apocalisp ^foo.*(?<!bar)$ Should match anything that starts with "foo" and doesn't end with "bar". I know about the [^...] syntax, but I can't find anything that will ...

Can you make just part of a regex case-insensitive?

I've seen lots of examples of making an entire regular expression case-insensitive. What I'm wondering about is having just part of the expression be case-insensitive. For example, let's say I have a string like this: fooFOOfOoFoOBARBARbarbarbAr What if I want to match all occurrences of "foo" regardless of case but I only want to ma...

Strip all HTML tags except links

I am trying to write a regular expression to strip all HTML with the exception of links (the <a href and </a> tags respectively. It does not have to be 100% secure (I am not worried about injection attacks or anything as I am parsing content that has already been approved and published into a SWF movie). The original "strip tags" regula...

Regex in VB6?

I need to write a program that can sift through specially-formatted text files (essentially CSV files with a fixed set of column types that have different delimiters for some columns ... comma in most places, colons in others) to search for formatting errors. I figure regular expressions will be the way to go. The question: Is there a...

RegEx to Detect SQL Injection

I'm looking for a good solid Regular Expression for detecting SQL in a string. Does anyone have a sample of something they've used before? ...

What are the Java regular expressions for matching IPv4 and IPv6 strings?

Looking for a string to pass to String#matches(String) that will match IPv4, and another to match IPv6. ...

Validate email address in Javascript?

What's the best way to validate an email address in Javascript? Though this solution may be simple, I'm sure this is one of those useful things that people will be Googling for and deserves its own entry on the site ...

How to Dynamically Generate String Validation?

Does anyone know of a library (preferably php) or algorithm for auto-generating regex's from some common descriptions? For example, have a form with the possible options of: Length (=x, between x & y, etc) Starts with Ends with Character(s) x(yz) at index i Specify one or more alternative behavior based on the above And so on.. The ...

Want to Encode text during Regex.Replace call

I have a regex call that I need help with. I haven't posted my regex, because it is not relevant here. What I want to be able to do is, during the Replace, I also want to modify the ${test} portion by doing a Html.Encode on the entire text that is effecting the regex. Basically, wrap the entire text that is within the range of the rege...

What code would I use to convert a SQL like expression to a regex on the fly?

I'm looking to convert a SQL like statement on the fly to the equivalent regex i.e. LIKE '%this%' LIKE 'Sm_th' LIKE '[C-P]arsen' What's the best approach to doing this? P.S. I'm looking to do this on the .Net Framework (C#). ...

Finding the phone numbers in 50,000 HTML pages

How do you find the phone numbers in 50,000 HTML pages? Jeff Attwood posted 5 Questions for programmers applying for jobs: In an effort to make life simpler for phone screeners, I've put together this list of Five Essential Questions that you need to ask during an SDE screen. They won't guarantee that your candidate w...

Regex to Match first 28 days of the month

I am looking for a Regular expression to match only if a date is in the first 28 days of the month. This is for my validator control in ASP.NET ...

What is a regex "independent capturing group"?

From the Java 6 Pattern documentation: Special constructs (non-capturing) (?:X)   X, as a non-capturing group … (?>X)   X, as an independent, non-capturing group Between (?:X) and (?>X) what is the difference? What does the independent mean in this context? ...

Regular Expression to match valid dates

I'm trying to write a regular expression that validates a date. The regex needs to match the following M/D/YYYY MM/DD/YYYY Single digit months can start with a leading zero (eg: 03/12/2008) Single digit days can start with a leading zero (eg: 3/02/2008) CANNOT include February 30 or February 31 (eg: 2/31/2008) So far I have ^(([1-9]...

Use cases for regular expression find/replace

I recently discussed editors with a co-worker. He uses one of the less popular editors and I use another (I won't say which ones since it's not relevant and I want to avoid an editor flame war). I was saying that I didn't like his editor as much because it doesn't let you do find/replace with regular expressions. He said he's never wa...

Dynamic regex for date time formats

Is there an existing solution to create regular expressions dynamically out of given date time format pattern? Supported date time format pattern does not matter (Joda DateTimeFormat, java.text.SimpleDateTimeFormat or others). i.e. for a given date-time format (for example "dd/MM/yyyy hh:mm"), it will generate corresponding regular exp...

Regular expression that matches valid IPv6 addresses

I'm having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with "::" or leading zeros omitted from each byte pair). Can someone suggest a regular expression that would fulfill the requirement? I'm considering expanding each byte pair and matching the result with a simp...

regex for parsing resource (.rc) files

Ulimately I just wanted to extract strings from the .rc file so I could translate them, but anything that goes with .rc files works for me. ...