流动的正则表达式有什么区别:
HEAD|GET
, (HEAD|POST)
& [HEAD|POST]
?
基本上,我想在 HEAD 或 POST 之后提取数字。
irb(main):001:0> "This is HEAD and a POST".match("HEAD|POST")
=> #<MatchData "HEAD">
irb(main):002:0> "This is HEAD and a POST".match("(HEAD|POST)")
=> #<MatchData "HEAD" 1:"HEAD">
irb(main):003:0> "This is HEAD and a POST".match("[HEAD|POST]")
=> #<MatchData "T">
irb(main):004:0> "This is HEAD 1 and a POST 2".match("[HEAD|POST] (.)")
=> #<MatchData "D 1" 1:"1">
irb(main):005:0>
最后一个正则表达式与“POST”之后的“2”不匹配。为什么?另外,为什么要匹配“D 1”?