regex

Is a good practice to use regular expression for input validation?

Currently I have some theoretically background in regular expression, but I have almost never used them. I am trying to develop some classes for general input validation, and I have being writing methods without any use of regular expressions. I recently read this Jeff's article, and now I am wondering if I should refactor some of the ...

Groovy syntax for regular expression matching

What is the Groovy equivalent of the following Perl code? my $txt = "abc : groovy : def"; if ($txt =~ / : (.+?) : /) { my $match = $1; print "MATCH=$match\n"; # should print "MATCH=groovy\n" } I know that TMTOWTDI (including the regular Java way) - but what is the "Groovy way" of doing it? This is one way of doing it, but it f...

What would be the Regular Expression to retrieve number in front of % symbol in string?

I'm using a math parser that uses % as the mod symbol. I'd like to use it for the percent symbol instead to allow users to type "25%*10" or "25% of 10" and receive the answer "2.5" (they could type anything). I'd then use the regex asked for to get the "25%" (could be in any part of the string) and do a simple calculation (25 / 100) an...

Can I substitute multiple items in a single regular expression in VIM or Perl?

Let's say I have string "The quick brown fox jumps over the lazy dog" can I change this to "The slow brown fox jumps over the energetic dog" with one regular expression? Currently, I use two sets of regular expressions for this situation. (In this case, I use s/quick/slow/ followed by s/lazy/energetic/.) thanks. ...

Python non-greedy regexes

How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"? I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"? ...

What is the longest possible Regex in Polynomial Time?

The question Complexity of Regex substitution nears the question, but it is not the same. According to the reply by theprise, the complexity (of a DFA engine) is: O(2^m + n) [where m is the length of the regex and n is the length of the string] The red book "Algorithm Design Manual" on page 15-16 discusses the time for different al...

Does Perl currently (5.8 and 5.10) make any promises about the order alternations will be used?

Given an alternation like /(foo|foobar|foobaz)/ does Perl 5.8 or 5.10 make any promises about which of the three will be used first, and if it does where in the documentation does it make that promise? See the related question Does Perl 6 make any promises about the order alternations will be used? ...

Using Regular Expressions with Javascript replace method

Friends, I'm new to both Javascript and Regular Expressions and hope you can help! Within a Javascript function I need to check to see if a comma(,) appears 1 or more times. If it does then there should be one or more numbers either side of it. e.g. 1,000.00 is ok 1,000,00 is ok ,000.00 is not ok 1,,000.00 is not ok If these...

How to Regex replace match group item with method result

The input string is something like this: LineA: 50 LineB: 120 LineA: 12 LineB: 53 I would like to replace the LineB values with a result of MultiplyCalculatorMethod(LineAValue), where LineAValue is the value of the line above LineB and MultiplyCalculatorMethod is my other, complicated C# method. In semi-code, I would like to do som...

Strip out all whitespace?

Hi, What's the best way to strip out all whitespace from a .Net website? I found this site Whitespace removal - 4Wall Art Site If you look at the source it's clearly a .net site but all unwanted tabs and spaces are removed. Now I've searched around it seems a regular expression on the page render is the best method but does anyone have...

Regular Expression Validation (Test) in JavaScript

It would seem that regular expression questions are common as each question seems to apply to a specific case. With that said, here is my specific case... I need to validate that an employee id is in one of two specific formats. The first format (and one that I have working reliably) is (w/o the quotes): "A000000" , where "A" can be ...

Replacing text using regular expression with variable text?

Lets say I have some text with lots of instances of word "Find", which I want to replace it with text like "Replace1","Replace2","Replace3", etc. The number is the occurrence count of "Find" in the text. How to do it in the most effective way in C#, I already know the loop way. ...

QTP/VBScript: How to remove all URLs from a string?

I have a string in my QTP test project. In some cases, this string is a plaintext E-mail's content; in other cases it's HTML. In both cases, I need to strip all URLs from the string to match it against an Expected case. How can this be done in QTP/VBScript? ...

T-SQL search html with regex?

In my database I have a field wich contains a html document. Now there must be a possibility to search in this document. However, the html tags may not be found. So when I have something like this: <html> <head> <title>Bar</title> </head> <body> <p> this content my be found </p> </body> </html> It is possible th...

Regular expression explained with words

I need a web page or Windows application that takes a regular expression and explains it to me in text what it does. Do you have any suggestions for such an application? ...

Substitution or replacement regular expressions

In an XML file, I am capturing a long list of URLS from a web page, using regex (in .NET). Within the captured URLS, I simply need to substitute '&' for all '&amp;' that are located within the URLS. How do I do this? ...

Use REGEX to find Contents of HTML ListItem (.NET)

Using the following text as a sample, I need to be able to extract text between LI tags. Notice that the first LI is intentionally mal-formed as this may be the case. Said another way, I want everything from an LI tag to either it's closing LI tag or the next LI opening tag. <UL> <LI class="test">This is the first ListItem Text. <...

Regex that validates Active Directory default password complexity

I have a list of passwords that I need to examine and determine if they meet the default 3 of 4 rule for AD. Rule is contain 3 of the 4 following requirements: lower case character (a-z) upper case character (A-Z) numeric (0-9) special character ( !@#$%^&()+= ) I am still learning Regex. I know how to select only those that meet any...

Good tutorials for learning intermediate to advanced Regex?

So I'm familiar with the basics of regex but am looking for good tutorials for learning anything beyond the basics. I'd also appreciate any links to interactive problems where I can type in regular expressions and see if they solve it. Even ideas for intermediate or advanced problems I can try and solve through my own coding would be gr...

php/regex: allow dashes in this pattern

How can I allow dashes in this pattern? $str = preg_replace ( "/[^a-z \d]/i", "", $str ) ; ...