Care to elaborate?
Hehe, ok
In this serialization they show as " ", #" ", but in the wx gui you can see these are merely PPIx::Regexp::Token::Whitespace=HASH(0x178d3f4)
So all you do is walk the tree and delete/remove stuff you dont want,
when done serialize and what you're left is the non /x version
html explanation
| # my $regstr = join '', ; # The regular expression (PPI::Token::Regexp::Substitute): ; # # s{ \d+ \w+ }{}gx # # matches as follows: #r: PPIx::Regexp / PPI::Token::Regexp::Substitute #r= "s{ \\d+ \\w+ }{}gx" # |
"s", |
# address=/1/C0 ; xRe::Token::Structure ; Represent structural elements. #"s", # ------------------------------------------------------------------ |
| # address=/1/C1 ; xRe::Structure::Regexp ; Represent the top-level regular expression # ------ |
"{", |
# address=/1/C1/S0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"{", # ------------------------------------------------------------------ |
" ", |
#" ", |
"\\d", |
# # address=/1/C1/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> #"\\d", # ---------- |
"+", |
# # address=/1/C1/C1 ; xRe::Token::Quantifier ; Represent an atomic quantifier. # match preceding pattern 1 or more times # (matching the most amount possible) # match the preceding pattern at address=/1/C1/C0 #"+", # ---------- |
" ", |
#" ", |
" ", |
#" ", |
" ", |
#" ", |
" ", |
#" ", |
"\\w", |
# # address=/1/C1/C6 ; xRe::Token::CharClass::Simple ; This class represents a simple character class # \w Match a "word" character. # L<perlrecharclass/\w> # \w matches [a-zA-Z0-9_]. # L<perldebguts/ALNUM> # L<perlrecharclass/\w> # L<perlrebackslash/\w> #"\\w", # ---------- |
"+", |
# # address=/1/C1/C7 ; xRe::Token::Quantifier ; Represent an atomic quantifier. # match preceding pattern 1 or more times # (matching the most amount possible) # match the preceding pattern at address=/1/C1/C6 #"+", # ---------- |
" ", |
#" ", |
"}", |
# address=/1/C1/F0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"}", # ------------------------------------------------------------------ |
| # address=/1/C2 ; xRe::Structure::Replacement ; Represent the replacement in s/// # ---- |
"{", |
# address=/1/C2/S0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"{", # ------------------------------------------------------------------ |
"}", |
# address=/1/C2/F0 ; xRe::Token::Delimiter ; Represent the delimiters of the regular expression #"}", # ------------------------------------------------------------------ |
"gx", |
# # address=/1/C3 ; xRe::Token::Modifier ; Represent 1)embedded pattern-match modifiers or 2)(trailing) modifiers for operators match, substitution, regexp constructor # /g Match globally, i.e., find all occurrences. # in list context (@matches=m//g) return all matches; in scalar context($count=m//g) return number of matches # /x disregarding whitespace and comments #"gx", # ------------------------------------------------------------------ |
| ;;;;;;;;;;
|
Here is text version from the gui it also shows xRe::Token::Comment
# my $regstr = join '', # # The regular expression (PPI::Token::Regexp::Substitute): # # # # s{ # # (?# probulary ) # # \d+ # digits # # [ ] # space # # \s+ # spaces # # \w+ # words # # }{}gx # # # # matches as follows: # #r: PPIx::Regexp / PPI::Token::Regexp::Substitute # #r= "s{\n(?# probulary )\n\\d+ # digits\n[ ] # space\n\\s+ # spac +es\n\\w+ # words \n}{}gx" # # # address=/3/C0 # xRe::Token::Structure # Represent structural elements. "s", # ------------------------------------------------------------------ # address=/3/C1 # xRe::Structure::Regexp # Represent the top-level regular expression # ------ # address=/3/C1/S0 # xRe::Token::Delimiter # Represent the delimiters of the regular expression "{", # ------------------------------------------------------------------ "\n", # address=/3/C1/S2 # xRe::Token::Comment "(?# probulary )", # ------------------------------------------------------------------ "\n", # address=/3/C1/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> "\\d", # ---------- # address=/3/C1/C1 # xRe::Token::Quantifier # Represent an atomic quantifier. # match preceding pattern 1 or more times # (matching the most amount possible) # match the preceding pattern at address=/3/C1/C0 "+", # ---------- " ", # address=/3/C1/C3 # xRe::Token::Comment "# digits\n", # ------------------------------------------------------------------ # address=/3/C1/C4 # xRe::Structure::CharClass # a character class # ------------ # address=/3/C1/C4/S0 # xRe::Token::Structure # Represent structural elements. "[", # ------------------------------------------------------------------ # address=/3/C1/C4/C0 # xRe::Token::Literal # a literal character # ordinal= ord( chr( 32 ) ) alias \N{U+0020} alias +\040 alias SPACE alias " ", # ------------------------------------------------------------------ # address=/3/C1/C4/F0 # xRe::Token::Structure # Represent structural elements. "]", # ------------------------------------------------------------------ " ", # address=/3/C1/C6 # xRe::Token::Comment "# space\n", # ------------------------------------------------------------------ # address=/3/C1/C7 # xRe::Token::CharClass::Simple # This class represents a simple character class # \s Match a whitespace character. # L<perlrecharclass/\s> # L<perlrebackslash/\s> "\\s", # ---------- # address=/3/C1/C8 # xRe::Token::Quantifier # Represent an atomic quantifier. # match preceding pattern 1 or more times # (matching the most amount possible) # match the preceding pattern at address=/3/C1/C7 "+", # ---------- " ", # address=/3/C1/C10 # xRe::Token::Comment "# spaces\n", # ------------------------------------------------------------------ # address=/3/C1/C11 # xRe::Token::CharClass::Simple # This class represents a simple character class # \w Match a "word" character. # L<perlrecharclass/\w> # \w matches [a-zA-Z0-9_]. # L<perldebguts/ALNUM> # L<perlrecharclass/\w> # L<perlrebackslash/\w> "\\w", # ---------- # address=/3/C1/C12 # xRe::Token::Quantifier # Represent an atomic quantifier. # match preceding pattern 1 or more times # (matching the most amount possible) # match the preceding pattern at address=/3/C1/C11 "+", # ---------- " ", # address=/3/C1/C14 # xRe::Token::Comment "# words \n", # ------------------------------------------------------------------ # address=/3/C1/F0 # xRe::Token::Delimiter # Represent the delimiters of the regular expression "}", # ------------------------------------------------------------------ # address=/3/C2 # xRe::Structure::Replacement # Represent the replacement in s/// # ---- # address=/3/C2/S0 # xRe::Token::Delimiter # Represent the delimiters of the regular expression "{", # ------------------------------------------------------------------ # address=/3/C2/F0 # xRe::Token::Delimiter # Represent the delimiters of the regular expression "}", # ------------------------------------------------------------------ # address=/3/C3 # xRe::Token::Modifier # Represent 1)embedded pattern-match modifiers or 2)(trailing) +modifiers for operators match, substitution, regexp constructor # /g Match globally, i.e., find all occurrences. # in list context (@matches=m//g) return all matches; in scalar + context($count=m//g) return number of matches # /x disregarding whitespace and comments "gx", # ------------------------------------------------------------------ # ;;;;;;;;;; # __END__ #PPIx::Regexp=HASH(0x179c8a4) s{ (?# probulary ) \d+ # digits [ ] # space \s+ # spaces \w+ # words }{}gx
Or maybe just copy http://search.cpan.org/perldoc/PPIx::Regexp::Node#find
and use the GUI is for interactive visualization.
$ perl -MPPIx::Regexp -MData::Dump -le " $r=PPIx::Regexp->new(q{s{ \d+ + \w+ }{}gx}); dd( $r ); print $r->content; " bless({ children => [ bless({ content => "s" }, "PPIx::Regexp::Token::Structure"), bless({ children => [ bless({ content => "\\d" }, "PPIx::Regexp::Token::CharClass::S +imple"), bless({ content => "+" }, "PPIx::Regexp::Token::Quantifier"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), bless({ content => "\\w" }, "PPIx::Regexp::Token::CharClass::S +imple"), bless({ content => "+" }, "PPIx::Regexp::Token::Quantifier"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), ], finish => [bless({ content => "}" }, "PPIx::Regexp::Token::Delim +iter")], max_capture_number => 0, start => [ bless({ content => "{" }, "PPIx::Regexp::Token::Delimiter"), bless({ content => " ", perl_version_introduced => "5.000" }, +"PPIx::Regexp::Token::Whitespace"), ], type => [], }, "PPIx::Regexp::Structure::Regexp"), bless({ children => [], finish => [bless({ content => "}" }, "PPIx::Regexp::Token::Del +imiter")], start => [bless({ content => "{" }, "PPIx::Regexp::Token::Del +imiter")], type => [], }, "PPIx::Regexp::Structure::Replacement"), bless({ content => "gx", modifiers => { g => 1, x => 1 } }, "PPIx: +:Regexp::Token::Modifier"), ], effective_modifiers => { g => 1, x => 1 }, failures => 0, source => "s{ \\d+ \\w+ }{}gx", }, "PPIx::Regexp") s{ \d+ \w+ }{}gx
In reply to Re^3: How to strip comments and whitespace from a regex defined with /x?
by Anonymous Monk
in thread How to strip comments and whitespace from a regex defined with /x?
by jh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |