regex

What is wrong with this PHP regular expression?

$output = preg_replace("|(/D)(/s+)(/d+)(;)|", "//1,//3;", $output); I'm trying to replace all alphabetical character followed by one or more whitespace characters (tabs and/or spaces) followed by one or more numerical characters followed by a semicolon with the alphabetical character followed by a comma followed by the numerical digits...

Regex's For Developers

I've been trying to figure out a regex to allow me to search for a particular string while automatically skipping comments. Anyone have an RE like this or know of one? It doesn't even need to be sophisticated enough to skip #if 0 blocks; I just want it to skip over // and /* blocks. The converse, that is only search inside comment blo...

Python regular expression for HTML parsing (BeautifulSoup)

I want to grab the value of a hidden input field in HTML. <input type="hidden" name="fooId" value="12-3456789-1111111111" /> I want to write a regular expression in Python that will return the value of fooId, given that I know the line in the HTML follows the format <input type="hidden" name="fooId" value="**[id is here]**" /> Can ...

What is the proper regular expression for an unescaped backslash before a character?

Let's say I want to represent \q (or any other particular "backslash-escaped character"). That is, I want to match \q but not \\q, since the latter is a backslash-escaped backslash followed by a q. Yet \\\q would match, since it's a backslash-escaped backslash followed by a backslash-escaped q. (Well, it would match the \q at the end,...

<asp:RegularExpressionValidator and RegexOptions.IgnorePatternWhitespace

Is there an easy way of using the RegularExpressionValidator control while ignoring white space? I can use a custom validator control with Regex and IgnorePatternWhitespace, but it would be good to just have an option in the RegularExpressionValidator control. ...

Emacs query-replace with textual transformation

I want to find any text in a file that matches a regexp of the form t[A-Z]u (i.e., a match t followed by a capital letter and another match u, and transform the matched text so that the capital letter is lowercase. For example, for the regexp x[A-Z]y xAy becomes xay and xZy becomes xzy Emacs' query-replace function allows bac...

Does re.compile() or any given Python library call throw an exception?

I can't tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that could be considered an invalid regular expression. The larger question is, where do I go to find if a given Python library call may throw exception(s) and what those are? ...

How to escape text for regular expression in Java

Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input. ...

improve my python regex!

What follows is a regular expression I have written to match multi-line pre-processor macros in C / C++ code. I'm by no means a regular expressions guru, so I'd welcome any advice on how I can make this better. Here's the regex: ^\s*#define(.*\\\n)+[\S]+(?!\\) It should match all of this: #define foo(x) if(x) \ doSomething(x) But ...

Regular expression that rejects all input?

Is is possible to construct a regular expression that rejects all input strings? ...

parsings strings: extracting words and phrases [JavaScript]

I need to support exact phrases (enclosed in quotes) in an otherwise space-separated list of terms. Thus splitting the respective string by the space-character is not sufficient anymore. Example: input : 'foo bar "lorem ipsum" baz' output: ['foo', 'bar', 'lorem ipsum', 'baz'] I wonder whether this could be achieved with a single RegE...

Caching compiled regex objects in Python?

Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles are spent compiling the strings into their representative state machines in memory. a = re.compile("a.*b") b = re.compile("c.*d") ... Question: Is it possible to store these regular expressions in a cache on disk in a pre-compi...

Multiline C# Regex to match after a blank line

I'm looking for a multiline regex that will match occurrences after a blank line. For example, given a sample email below, I'd like to match "From: Alex". ^From:\s*(.*)$ works to match any From line, but I want it to be restricted to lines in the body (anything after the first blank line). Received: from a server Date: today To: Ted ...

Regex that Will Match a Java Method Declaration

I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to be on the same line as the declaration. If you have any suggestions to improve my regex or simply have a better one then please submit an answer. Here is my regex: "...

How do I create a regex in emacs for exactly 3 digits?

I want to create a regexp in emacs that matches exactly 3 digits. For example, I want to match the following: 123 345 789 But not 1234 12 12 23 If I use [0-9]+ I match any single string of digits. I thought [0-9]{3} would work, but when tested in re-builder it doesn't match anything. ...

Whats the best way to store and retrive postal addresses using a sql server database and the .NET framework?

I'm looking for a common pattern that will store and access global addresses in database. Components or other technologies can be used. The following criteria must be adheard to... Every line of the address is saved for every country Postal codes are tested with a regular expression before being saved Country of original is saved in ...

Python and "re"

A tutorial I have on Regex in python explains how to use the re module in python, I wanted to grab the URL out of an A tag so knowing Regex I wrote the correct expression and tested it in my regex testing app of choice and ensured it worked. When placed into python it failed. After much head scratching I found out the issue, it automati...

What's the best approach to embed RegEx in Oracle or SQL Server 2005 SQL?

This is a 3 part question regarding embedded RegEx into SQL statements. How do you embed a RegEx expression into an Oracle PL/SQL select statement that will parse out the “DELINQUENT” string in the text string shown below? What is the performance impact if used within a mission critical business transaction? Since embedding regex into...

How to cycle through delimited tokens with a Regular Expression?

How can I create a regular expression that will grab delimited text from a string? For example, given a string like text ###token1### text text ###token2### text text I want a regex that will pull out ###token1###. Yes, I do want the delimiter as well. By adding another group, I can get both: (###(.+?)###) ...

Regex for Specific Tag

Greetings! I'm working on a regular expression in a .NET project to get a specific tag. I would like to match the entire DIV tag and its contents: <html> <head><title>Test</title></head> <body> <p>The first paragraph.</p> <div id='super_special'> <p>The Store paragraph</p> </div> </body> </head> C...