Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个如何匹配所有\b不是“=”的?
\b
"igloo".match(...) # => `igloo` "igloo=".match(...) # => `nil`
首先,\b不匹配'=';它匹配 '=' 和其他东西之间的边界。要仅在边界的另一侧不是“=”时匹配,请使用负前瞻:
rx = /igloo\b(?!=)/ "igloo".match(rx) => #<MatchData "igloo"> "igloo=".match(rx) => nil
这就是说“匹配一个 \b 边界,但仅当后面没有'='时”。