如何在 Javascript 中匹配 U1234 而不是\U1234?
我不知道如何不匹配单个反斜杠。 我能得到的最接近的是:
\[\\]{0}U[0-9]{4}\b
但这行不通。 有什么建议吗?
最佳答案
JavaScript 绝对不支持后向断言。在我看来,下一个获得你想要的东西的最佳方式是
(?:^|[^\\])(U[0-9]{4})
解释:
(?: # non-capturing group - if it matches, we don't want to keep it
^ # either match the beginning of the string
| # or
[^\\] # match any character except for a backslash
) # end of non-capturing group
(U\d{4}) # capturing group number 1: Match U+4 digits
关于Javascript正则表达式匹配字符串,除非前面有反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1381697/