Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Created May 16, 2012 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicerobot/2706343 to your computer and use it in GitHub Desktop.
Save nicerobot/2706343 to your computer and use it in GitHub Desktop.
Debug RE with perl
http://stackoverflow.com/questions/2348694/how-do-you-debug-a-regex/2348725#2348725
$ perl -Mre=debugcolor -e 'm/.../'
Compiling REx "..."
Final program:
1: REG_ANY (2)
2: REG_ANY (3)
3: REG_ANY (4)
4: END (0)
minlen 3
Freeing REx: "..."
$ perl -Mre=debugcolor -e 'm/^.(?:[X.]{4})../'
Compiling REx "^.(?:[X.]{4}).."
Final program:
1: BOL (2)
2: REG_ANY (3)
3: CURLY {4,4} (16)
5: ANYOF[.X] (0)
16: REG_ANY (17)
17: REG_ANY (18)
18: END (0)
anchored(BOL) minlen 7
Freeing REx: "^.(?:[X.]{4}).."
$ perl -Mre=debugcolor -e 'm/^.(?:[[:space:]]{4})../'
Compiling REx "^.(?:[[:space:]]{4}).."
Final program:
1: BOL (2)
2: REG_ANY (3)
3: CURLY {4,4} (17)
5: ANYOF[\11-\15 +utf8::IsSpace] (0)
17: REG_ANY (18)
18: REG_ANY (19)
19: END (0)
anchored(BOL) minlen 7
Freeing REx: "^.(?:[[:space:]]{4}).."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment