javascript - chrome.declarativeContent.PageStateMatcher 中的正则表达式

标签 javascript regex google-chrome-extension

我需要在我的 chrome.declarativeContent.PageStateMatcher 中添加一些正则表达式。

到目前为止我有

var matcher = new chrome.declarativeContent.PageStateMatcher({
    pageUrl: {
         urlContains: "something.com/someRegex/something"

    }
 });

基本上我想要一个正则表达式来评估“something.com/4-5 char string/somithing”。

我该怎么做?这可能与 chrome.declarativeContent.PageStateMatcher 有关吗?

谢谢

最佳答案

而不是 urlContains 使用 urlMatches

这就是我在域 fedmich.com 和 fedche.com 上使用的内容

chrome.runtime.onInstalled.addListener(function() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    chrome.declarativeContent.onPageChanged.addRules([
      {
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlMatches: '(fedmich|fedche)\.com' },
          })
        ],
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});

文档在这里 https://developer.chrome.com/extensions/events#property-UrlFilter-hostEquals

正则表达式使用 RE2 语法。 https://code.google.com/p/re2/wiki/Syntax

关于javascript - chrome.declarativeContent.PageStateMatcher 中的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22309283/

相关文章:

c# - 在 C# 中允许反斜杠的正则表达式

javascript - 在 OR 中将正则表达式组合在一起?

php - 如何忽略搜索引擎在 PHP 页面上的综合浏览量?

google-chrome - 使用Cookie从Chrome扩展程序发送XHR请求

javascript - API 调用失败时在浏览器控制台中显示错误是否不好?

javascript - 使用文件系统将 ANSI 文件文本转换为 node.js 中的 UTF8

javascript - Mapbox如何通过鼠标滚动控制 map 缩放速度

javascript - Django 管理员预填充字段不是错误 "d.Keyup is not a function"

javascript - 如何让某些代码只在某些特定域上运行

google-chrome - 如何从内容脚本获取事件页面?