将greasemonkey通配符转换为正则表达式
是否有一个简单的替换函数可以将greasemonkey通配符更改为正则表达式模式?
我想将 'http://www.google.com/*/index.html'
转换为 /^http://www.google.com\/\w\/index .html$/
我希望能够使用 javascript 中的 greasmonkey 通配符测试 url
Is there a simple replace function that will change a greasemonkey wildcard into a regular expression pattern?
I want to convert 'http://www.google.com/*/index.html'
into /^http://www.google.com\/\w\/index.html$/
I want to be able to test the url with a greasmonkey wildchar in javascript
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,我可能还没有用尽通配符的所有选项(我也没有一个巨大的测试数据库进行试验),但这是我想出的:
用法:
Granted I probably haven't exhausted all options of wildcards (nor have I had a huge test database for trials) but here's what I've come up with:
Usage:
将
@include/@exclude
转换为 reg exp 的代码是 这里。但所发生的只是
*
被.*
替换,并且[
、(
等字符被转换到\[
,\(
,然后string
被发送到new RegExp(string)
。如果您使用Scriptish 那么您可以使用
@ 的正则表达式语法include/@exclude
s,就像这样The code which converts a
@include/@exclude
to a reg exp is here.All that happens though is that
*
is replaced with.*
and characters like[
,(
, etc are converted to\[
,\(
, then thestring
is sent tonew RegExp(string)
.If you used Scriptish then you can use regular expression syntax for the
@include/@exclude
s, like so只需看看 油猴的来源
Just have a look at Greasemonkey's source