Sunday, May 3, 2009

Name that regex

What do these regular expressions match?

  1. /0x[0-9A-Fa-f]+/

  2. /\-?\d+/

  3. /\/{2}.*?\n|\/\*.*?\*\//

  4. /<!\-{2}.*?\-{2}>/

  5. /^\d{5}(\-\d{4})?$/

  6. /[A-Za-z_][A-Za-z0-9_]*/

2 comments:

Andy said...

I'll bite.

# /0x[0-9A-Fa-f]+/

a hex number in a language like C.

# /\-?\d+/

signed int

# /\/{2}.*?\n|\/\*.*?\*\//

C/C++ comment

# /<!\-{2}.*?\-{2}>/

html comment

# /^\d{5}(\-\d{4})?$/

area code

# /[A-Za-z_][A-Za-z0-9_]*/

identifier in a programming language

Ugh, blogger.com is retarded:
"Your HTML cannot be accepted: PHP, ASP, and other server-side scripting is not allowed."
Instead of just escaping.

thejoshwolfe said...

win! assuming s/area/zip/