在Greasemonkey @include中使用正则表达式? [英] Using a regular expression in a Greasemonkey @include?
问题描述
我想指定Greasemonkey脚本运行的位置.
I want to specify a bit better where my Greasemonkey script runs.
// @include https://example.com/*
工作正常,但是它太不准确了,我想要类似的东西:
Works fine, but it is too inaccurate, I want something like:
// @include https://example.com/xx-xx/Asset/*
xx可以是字母a-z,-只是破折号,xx可以是字母a-z.我的想法是对任何5个符号使用正则表达式,但我不知道如何正确使用它.这是行不通的,我尝试过表达更多的表情:
xx could be any letter a-z, - is just dash, xx could be any letter a-z. My Idea was use regular expression for any 5 symbols, but I don't know how to properly use it. This is not working and lot more expression which I have tried to:
// @include https://example.com/...../Asset/*
您知道如何处理吗?
更新:
这类作品:
Update:
This sort of works:
// @include https://example.com/*/Asset/*
推荐答案
请参阅Greasemonkey中的 包含和排除规则文档.
*
是一个特殊的通配符,不是按照通常的javascript规则.
要使用功能强大的正则表达式, Greasemonkey提供 @include
的特殊语法.
See Include and exclude rules in the Greasemonkey documentation.
*
is a special wildcard, NOT per the usual javascript rules.
To use full-powered regular expressions, Greasemonkey provides a special syntax for @include
.
所以您的https://example.com/xx-xx/Asset/*
模式将变为:
// @include /^https:\/\/example\.com\/[a-z]{2}\-[a-z]{2}\/Asset\/.*$/
您可以在RegExr.com上查看该正则表达式的解释.
You can see an explanation of that regex at RegExr.com.
这篇关于在Greasemonkey @include中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!