我发现该YAPE::Regex::Explain
模块非常有用 -
C:\>perl -e "use YAPE::Regex::Explain;print YAPE::Regex::Explain->new(qr/['-])->explain;" The regular expression: (?-imsx:['-]) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ['-] any character of: ''', '-' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- C:\>perl -e "use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr/(\w+), ?(.)/)->explain;" The regular expression: (?-imsx:(\w+), ?(.)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- , ',' ---------------------------------------------------------------------- ? ' ' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- C:\>
tvanfosson.. 10
我将这些备忘单中的一张固定在我的立方体墙上以备这种情况.谷歌regular expression cheat sheet
寻找其他人.
添加到您已经知道的内容:
g -- search globally throughout the string + -- match at least one, but as many as possible ? -- match 0 or 1 . -- match any character () -- group these together , -- a plain comma, no special meaning [] -- match any character inside the brackets \w -- match any word character
神奇的是分组 - 匹配表达式使用组并将它们放入变量$ 1和$ 2.在这种情况下,$ 1匹配逗号前的单词,$ 2匹配逗号后面的空白后面的第一个字符.
我发现该YAPE::Regex::Explain
模块非常有用 -
C:\>perl -e "use YAPE::Regex::Explain;print YAPE::Regex::Explain->new(qr/['-])->explain;" The regular expression: (?-imsx:['-]) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ['-] any character of: ''', '-' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- C:\>perl -e "use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr/(\w+), ?(.)/)->explain;" The regular expression: (?-imsx:(\w+), ?(.)) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- , ',' ---------------------------------------------------------------------- ? ' ' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- C:\>
我将这些备忘单中的一张固定在我的立方体墙上以备这种情况.谷歌regular expression cheat sheet
寻找其他人.
添加到您已经知道的内容:
g -- search globally throughout the string + -- match at least one, but as many as possible ? -- match 0 or 1 . -- match any character () -- group these together , -- a plain comma, no special meaning [] -- match any character inside the brackets \w -- match any word character
神奇的是分组 - 匹配表达式使用组并将它们放入变量$ 1和$ 2.在这种情况下,$ 1匹配逗号前的单词,$ 2匹配逗号后面的空白后面的第一个字符.