Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分正则表达式在手机浏览器中无法解析 #50

Open
fkworld opened this issue Jun 10, 2020 · 3 comments
Open

部分正则表达式在手机浏览器中无法解析 #50

fkworld opened this issue Jun 10, 2020 · 3 comments

Comments

@fkworld
Copy link
Owner

fkworld commented Jun 10, 2020

No description provided.

@fkworld
Copy link
Owner Author

fkworld commented Jun 11, 2020

复现方式:

let reg = /(?<=ap)ple/;
console.log(reg.test("apple"), reg.test("people"));

在桌面浏览器中输出:
true true

在手机浏览器中直接报错。
SyntaxError: Invalid regular expression: invalid group specifier name

@fkworld
Copy link
Owner Author

fkworld commented Jun 11, 2020

可能出现问题的原因:

  1. 浏览器不支持逆序肯定环视:https://segmentfault.com/q/1010000018521802?sort=created (最有可能)
  2. 灾难性回溯:https://zhuanlan.zhihu.com/p/44425997
  3. 其他原因:https://imweb.io/topic/567fca7c834878282edc7f99

@fkworld
Copy link
Owner Author

fkworld commented Jun 11, 2020

可以确定是某些浏览器不支持环视。

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Browser_Compatibility

可以从中看到 lookbehind assertions ((?<= ) and (?<! )) 这一项,部分浏览器是不支持的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant