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.
几个小时以来,我一直在努力让这种消极的前瞻性为我工作。只有当它后面没有'/CCC'时它才应该匹配我的字符串
http://refiddle.com/1xb
/(^[\w]+)(?!./CCC$)/mg
测试字符串:
BBB/CCC AAA/DDD/CCC
有人能指出为什么我的模式仍然匹配第一行的“BBB”吗?
首先,您必须转义/正则表达式的内部。
/
您还有一个不应该存在的点并且缺少单词边界:
/(^\w+)\b(?!\/CCC$)/mg
重提