I'm trying to filter every string which are not valid (simple) email adress. Thus starting with a dot is a "no go".  But my expression doesn't reject strings like .test@test.be  preg_match('/^(?&lt;!\.)[\w0-9\.]+(?&lt;!\.)@+(?&lt;!\.)[\w0-9\.]+\.\w{1,3}(\s*&lt;[^&gt;]+&gt;)?$/', $part)  Shouldn't /^(?&lt;!\.) do the trick?  EDIT: This question is not a duplicate of the indicated question.  I am not asking about the context, I want more information about look behind, the approach itself, not the specific use-case.
835
Over the years I have slowly developed a  that validates MOST email addresses correctly, assuming they don't use an IP address as the server part.  I use it in several PHP programs, and it works most of the time.  However, from time to time I get contacted by someone that is having trouble with a site that uses it, and I end up having to make some adjustment (most recently I realized that I wasn't allowing 4-character TLDs).  What is the best regular expression you have or have seen for validating emails?  I've seen several solutions that use functions that use several shorter expressions, but I'd rather have one long complex expression in a simple function instead of several short expression in a more complex function.
591
I am tired of always trying to guess, if I should escape special characters like '()[]{}|' etc. when using many implementations of regexps.  It is different with, for example, Python, sed, grep, awk, Perl, rename, Apache, find and so on. Is there any rule set which tells when I should, and when I should not, escape special characters? Does it depend on the regexp type, like PCRE, POSIX or extended regexps?
96773
I was just browsing a forum and someone asked about a PHP file they had found on the web.  It has several spots like this in the code:  if ($REMOTE_ADDR == "") $ip = "no ip"; else $ip = getHostByAddr($REMOTE_ADDR);  I have always thought brackets are needed to enclose what you want to do if the condition is true.  Is there some other alternative, such as if it is on the same line you don't?  There is also another line like this: if ($action != ""): mail("$adminaddress","Visitor Comment from YOUR SITE",  My instinct is to say this wouldn't work, but I also don't know if it is an outdated PHP file and it used to work?
39060
Whenever I try to insert " or ' I have to validate it by space, otherwise strange things happen as with ' followed by an a becomes áinstead of just 'a, similar behaviour with double quotes. I find this annoying and want to disable it. How do I do that?
86651
ab&amp;2e;1652769179"/>   i did correlction using rerular expression ab&amp;2e;(.*?)"/>  but during execution some times extra text (cd&amp;3d;) adding to the data like  ab&amp;2e;cd&amp;3d;1652769179"/>  So need to ignore data "cd&amp;3d;"  Please let me know any idea to ignore text cd&amp;3d; and capture 1652769179 only using expresiion ab&amp;2e;(.*?)"/>  Thanks Raghav
118631
A friend asked me this and I was stumped: Is there a way to craft a regular expression that matches a sequence of the same character? E.g.,  match on 'aaa', 'bbb', but not 'abc'?  m|\w{2,3}|    Wouldn't do the trick as it would match 'abc'.  m|a{2,3}|    Wouldn't do the trick as it wouldn't match 'bbb', 'ccc', etc.
41641
What is the most efficient way of testing an input string whether it contains a numeric value (or conversely Not A Number)? I guess I can use Double.Parse or a regex (see below) but I was wondering if there is some built in way to do this, such as javascript's NaN() or IsNumeric() (was that VB, I can't remember?).  public static bool IsNumeric(this string value) {     return Regex.IsMatch(value, "^\\d+$"); }
111242
I have a , 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:        But not match something like this:      So, I thought my best bet was something like this:    /(.+)/(\d{4}-\d{2}-\d{2})-(\d+)[/$]   where the character class at the end contained either the "/" or the end-of-line. The character class doesn't seem to be happy with the "$" in there though. How can I best discriminate between these URLs while still pulling back the correct groups?
32741
The  states that:     Since 1.0.4, case insensitive regular expressions can be used by prefixing the pattern with ~*.   And gives the example:  map $uri $myvalue {     /aa                   /mapped_aa;     ~^/aa/(?&lt;suffix&gt;.*)$  $suffix; }   I updated to nginx/1.2.7 to make use of this, and naive regexes work okay, but variables don't. When I try the above syntax I get the error:  nginx: [emerg] pcre_compile() failed: unrecognized character after (?&lt; in "^/aa/(?&lt;suffix&gt;.*)$" at "suffix&gt;.*)$"   I also tried the following syntaxes, but none of them worked:  ~^(.*)$  $1; ~^(.*)$  \1;   but neither of them worked either.  Does anyone know how to get variables to work in regular expressions in HttpMapModule?
54053
Why do PHP regexes have the surrounding delimiters? It seems like it would be more clear if any pattern modifiers were passed in as a parameter to whatever function was being used.
1578
I've tried using the - (not) symbol in searches on Stack Overflow to reduce the number of irrelevant matches in the results, with no effect.    I'm getting really sick of "Whats your favorite programmer joke / cartoon?" appearing in the results for almost every search I perform.  I've read  and there is no mention of how to use a Not operator to exclude the following word.  I've heard about excluding tags using -, but I'm talking about excluding words.  Is this possible?  Has it just not been implemented?  If not, I'd really like to see this added to search.
90846
I allow users to enter a regular expression to match IP addresses, for doing an IP filtration in a related system. I would like to validate if the entered regular expressions are valid as a lot of userse will mess op, with good intentions though.  I can of course do a Regex.IsMatch() inside a try/catch and see if it blows up that way, but are there any smarter ways of doing it? Speed is not an issue as such, I just prefer to avoid throwing exceptions for no reason.
2940
How can I test if a RegEx matches a string exactly?  var r = /a/; r.test("a"); // returns true r.test("ba"); // returns true testExact(r, "ba"); // should return false testExact(r, "a"); // should return true
15365
In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original?  I usually just copy the string to a new variable then bind it to the s/// regex that does the replacement on the new string, but I was wondering if there is a better way to do this?  $newstring = $oldstring; $newstring =~ s/foo/bar/g;
39428
I'm looking to find records in a table that match a specific number that the user enters.  So, the user may enter 12345, but this could be 123zz4-5 in the database. I imagine something like this would work, if PHP functions worked in MySQL. SELECT * FROM foo WHERE preg_replace(&quot;/[^0-9]/&quot;,&quot;&quot;,bar) = '12345'  What's the equivalent function or way to do this with just MySQL? Speed is not important.
91767
I've setup a very specific function and it works well but I'd like to make the parameters optional but I can't get a handle on the regex bit:  add_rewrite_rule('whats-on/([^/]+)/([^/]+)/([^/]+)/?$', 'index.php?page_id=71&amp;event_year=$matches[1]&amp;event_month=$matches[2]&amp;event_day=$matches[3]','top');   /whats-on/2012/01/25 I'll show all events on this date.  /whats-on/2012/01 goes to 404 but I'd like the parameter to be optional so I can show all January dates and the same for /whats-on/2012 all dates in year 2012  Any help will gratefully received - thanks
107897
I've been battling the following two questions for more than a day today.  Write a regular expression (comprised of {a, b}) that contain at least two b and do not contain abb. Write a regular expression (comprised of {a, b}) that contain abba and do not contain baa.  For the first part I wrote a basic one to start off with that doesn't handle the must two-b: b* OR a* OR (a+ AND b)* OR a*  I ran a few &quot;truth tables&quot; inputs over it and it seems ok. But the moment I add the requirement, things go haywire. Mostly because when pushing in those &quot;b&quot;s, you can suddenly use the OR to break things up. Same thing on the second one.... Any help would be greatly appreciated! Norah