News for hackers. Stuff that matters.
Re:I don't know Regex by irahul on Tuesday September 03, 2013 @03:38AM (#6319559)
Nice work. Personally I will still use the raw regex rather than the method calls to build the regular expression. As another commenter pointed out, the example regex is complex than it should be. It can be reduced to:

    pat = re.compile(r'^ \w+ @ [A-Za-z]\w*  \. \w+ $', re.X)
    if pat.match('[email protected]'):
        print "woot"
I won't bother explaining this regex(too simple). However, if it were something complex, I would put inline comments:

    pat = re.compile(r'''^ \w+  # rahul
                    @
                    [A-Za-z]\w*  # thoughtnirvana
                    \.
                    \w+ # com
                    $''',
                    re.X)
Notes about the example regex:

  var regEx = {(?:^)[A-Za-z]([A-Za-z]+|(?:\d+))(@{1,1})[A-Za-z]+(.{1,1})[A-Za-z]+(?:$)}
(?:^), (?:$) - This is the same as simply using ^. It isn't captured by default so there isn't a need to mark it non-capturing.

([A-Za-z]+|(?:\d+)) - What's going on here? You have a capturing group and within that capturing group, you have the or part marked as non capturing. What's the intent?

(@{1,1}) - @{1,1} is the same as @. Also, why are you capturing it? I think you are using parens for making the regex readable. You should use the IgnorePatternWhitespace instead http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx

Re:I don't know Regex by masklinn on Tuesday September 03, 2013 @04:03AM (#6319652)
Seems to me the example regex is the (completely broken) output of the (completely broken) generator expression below.
Re:I don't know Regex by jobigoud on Tuesday September 03, 2013 @04:17AM (#6319700)
Oh… that would explain a lot. It does have that "generated by a tool" useless verbosity feel to it.
Re:I don't know Regex by simpleigh on Tuesday September 03, 2013 @04:26AM (#6319729)
Unless I'm being daft, it can't be reduced to that at all. Dropping matching brackets, removing redundant {1,1} blocks, and escaping the \. we get down to:

    ^[A-Za-z]([A-Za-z]+|\d+)@[A-Za-z]+\.[A-Za-z]+$
Your version isn't the same at all - \w allows letters digits and underscores anywhere, whereas the original is more subtle.
Re:I don't know Regex by simpleigh on Tuesday September 03, 2013 @04:33AM (#6319757)
... and ignoring case obviously gets us down here:

    ^[a-z]([a-z]+|\d+)@[a-z]+\.[a-z]+$
Re:I don't know Regex by irahul on Tuesday September 03, 2013 @04:46AM (#6319795)
Yes. If you are going for equivalent, this would be it:

  pat = re.compile(r'^ [a-z] [a-z0-9]* @ [a-z]+ \. [a-z]+ $', re.I | re.X)
I took a few liberties in crafting the reduction.