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

正则表达式 - 性价比高的“小语种” #250

Open
zhanhongtao opened this issue Jun 21, 2017 · 0 comments
Open

正则表达式 - 性价比高的“小语种” #250

zhanhongtao opened this issue Jun 21, 2017 · 0 comments

Comments

@zhanhongtao
Copy link
Owner

zhanhongtao commented Jun 21, 2017

脚本语言(js/py/php/...)里面基本都内置支持了正则表达式,处理字符串能力极其强大,并且平时编辑器里面也有支持正则表达式的操作(见 #242,编辑器支持正则查找/替换)。

今天在看 Fiddler 的重定向(见 #247),里面使用了 .net 语法的正则表达式,就过去看了下。里面有 ES6 就要支持的捕获到变量名(不支持叫什么,就是之前都是 $0, $1, $2, ..., 现在可以 (?<var>...) 这样, 然后在正则中可以 \k<var> 这样引用, 在 JavaScript 中使用 group.var 引用变量,在 replace 中使用 $<var> 引用, 以及 replace(reg, function(m, p1, p2, i, string, object) {} 使用),还有 (?<=...(?<!...) 环视。各种语言都差不多...

ES6 里面支持了 y u s 修饰符,

  • y 每次匹配是都认为 lastIndex 是开头
  • u 支持了 unicode 字符
  • s 用来完善 .不支持 \n 的不足

感觉像正则表达式一样性价比高的还有各种配置文件格式/解析 - 比如: markdown/hosts/yaml/ini...
如果熟悉之后,再各种场景都可能会用到...

🚰

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

No branches or pull requests

1 participant