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

我有更好的正则: html注释 #20

Closed
xinglie opened this issue Aug 5, 2019 · 5 comments
Closed

我有更好的正则: html注释 #20

xinglie opened this issue Aug 5, 2019 · 5 comments

Comments

@xinglie
Copy link

xinglie commented Aug 5, 2019

html的注释正则应该是 /<!--[\s\S]*?-->/

html注释以-->结束,可以在中间,另外注释中可以回车换行,.并不匹配换行

@any86
Copy link
Owner

any86 commented Aug 5, 2019

十分感谢指正了2处错误 👍

"html注释以-->结束,可以在中间"这句没懂, 什么可以在中间?

@xinglie
Copy link
Author

xinglie commented Aug 5, 2019

因为你原本的正则是/<!--(.*?)-->$/
请问这里面的$是干什么用的?

@any86
Copy link
Owner

any86 commented Aug 5, 2019

/<!--(.*?)-->/.test(`<!-- <a>123</a> -->123`) // true

为了避免这种情况

@xinglie
Copy link
Author

xinglie commented Aug 5, 2019

避免?我知道了,你应试是要求输入的整个字符串都是html注释是吧
那应该是/^<!--[\s\S]*?-->$/首尾都要加上限定,不然你的也会出这样的情况

/<!--(.*?)-->$/.test(`123<!-- <a>123</a> -->`) //true

@any86
Copy link
Owner

any86 commented Aug 5, 2019

是的^忘记写了.多谢哦😯

any86 added a commit that referenced this issue Aug 5, 2019
* origin/master:
  fix: 修复"html注释"缺少的"^" (#20)
  Update README.md
  Update README.md
  Update README.md
  [ImgBot] Optimize images

# Conflicts:
#	packages/www/src/RULES.js
@any86 any86 closed this as completed Aug 5, 2019
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

2 participants