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.
我有字符串asdf-zxcv-qwer-
asdf-zxcv-qwer-
- 我想替换我正在使用的所有单词之间的所有出现/-[a-z]+-/It match only zxcv,因为连字符 beforeqwer用作前缀 after zxcv。如何使它同时匹配zxcv和qwer?
-
/-[a-z]+-/
zxcv
qwer
使用一个断言,可以是look-behind ( (?<=…)) 或look-ahead assertion ( (?=…)),它被检查但不被使用:
(?<=…)
(?=…)
/(?<=-)[a-z]+-/ /-[a-z]+(?=-)/