in reply to need help with a Perl regular expression
perlrequick, perlintro, Re^3: My Favourite Regex Tools (Was: Parsing a Variable Format String)
#~ two digits, #~ followed by a dash, #~ followed by an optional digit, #~ followed by four digits use Regexp::English; my $re = Regexp::English -> new -> digit -> digit -> literal('-') -> optional -> digit -> end -> digit -> digit -> digit -> digit; print $re; __END__ (?^:\d\d\-(?:\d?)\d\d\d\d)
rxrx describes the regex
\d Match a digit \d Match a digit \- Match a literal '-' character (?: The start of a non-capturing group \d? Match a digit, one-or-zero times (as many as possible +) ) The end of non-capturing group \d Match a digit \d Match a digit \d Match a digit \d Match a digit
wxPPIxregexplain.pl / ppixregexplain.pl says
| # my $regstr = join '', ; # The regular expression (PPI::Token::Regexp::Match): ; # # /(?^:\d\d\-(?:\d?)\d\d\d\d)/ # # matches as follows: #r: PPIx::Regexp / PPI::Token::Regexp::Match #r= "/(?^:\\d\\d\\-(?:\\d?)\\d\\d\\d\\d)/" # |
"", |
# address=/1/C0 ; xRe::Token::Structure ; Represent structural elements. #"", # ------------------------------------------------------------------ |
| # # address=/1/C1 ; xRe::Structure::Regexp ; Represent the top-level regular expression # perl_version_introduced=5.013006 # ------ |
"/", |
# address=/1/C1/S0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"/", # ------------------------------------------------------------------ |
| # # address=/1/C1/C0 ; xRe::Structure::Modifier ; Represent modifying parentheses # group but do not capture; Basic clustering # perl_version_introduced=5.013006 # ------------ |
"(", |
# address=/1/C1/C0/S0 ; xRe::Token::Structure ; Represent structural elements. #"(", # ------------------------------------------------------------------ |
"?^:", |
# # address=/1/C1/C0/T0 ; xRe::Token::GroupType::Modifier ; Represent the modifiers in a modifier group. # perl_version_introduced=5.013006 # mods( match_semantics = d x = 0 m = 0 s = 0 i = 0 ) # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"?^:", # ------------------------------------------------------------------ |
"\\d", |
# # address=/1/C1/C0/C0 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
"\\d", |
# # address=/1/C1/C0/C1 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
"\\-", |
# # address=/1/C1/C0/C2 ; xRe::Token::Literal ; a literal character # ordinal= ord( chr( 45 ) ) alias \N{U+002D} alias \055 alias HYPHEN-MINUS alias - # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\-", # ------------------------------------------------------------------ |
| # # address=/1/C1/C0/C3 ; xRe::Structure::Modifier ; Represent modifying parentheses # group but do not capture; Basic clustering # ------------------ |
"(", |
# address=/1/C1/C0/C3/S0 ; xRe::Token::Structure ; Represent structural elements. #"(", # ------------------------------------------------------------------ |
"?:", |
# address=/1/C1/C0/C3/T0 ; xRe::Token::GroupType::Modifier ; Represent the modifiers in a modifier group. #"?:", # ------------------------------------------------------------------ |
"\\d", |
# # address=/1/C1/C0/C3/C0 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; # (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; # (?d) is the old, problematic, pre-5.14 Default character set behavior. Its only use is to force that old behavior. #"\\d", # ---------------------- |
"?", |
# # address=/1/C1/C0/C3/C1 ; xRe::Token::Quantifier ; Represent an atomic quantifier. # match preceding pattern 0 or 1 times; is optional # (matching the most amount possible) # match the preceding pattern at address=/1/C1/C0/C3/C0 #"?", # ---------------------- |
")", |
# address=/1/C1/C0/C3/F0 ; xRe::Token::Structure ; Represent structural elements. #")", # ------------------------------------------------------------------ |
"\\d", |
# # address=/1/C1/C0/C4 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
"\\d", |
# # address=/1/C1/C0/C5 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
"\\d", |
# # address=/1/C1/C0/C6 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
"\\d", |
# # address=/1/C1/C0/C7 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \d Match a decimal digit character. # [0-9] # L<perldebguts/DIGIT> # L<perlrecharclass/\d> # L<perlrebackslash/\d> # (?^) is (?d) is "Depends" or "Dodgy" or "Default"; L<perlunicode/The "Unicode Bug">; #"\\d", # ---------------- |
")", |
# address=/1/C1/C0/F0 ; xRe::Token::Structure ; Represent structural elements. #")", # ------------------------------------------------------------------ |
"/", |
# address=/1/C1/F0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"/", # ------------------------------------------------------------------ |
"", |
# address=/1/C2 ; xRe::Token::Modifier ; Represent 1)embedded pattern-match modifiers or 2)(trailing) modifiers for operators match, substitution, regexp constructor #"", # ------------------------------------------------------------------ |
| ;;;;;;;;;;
|
|
|---|