简体   繁体   English

正则表达式-查找除某些模式以外的所有唯一字符串

[英]Regex - Find all unique strings excluding some patterns

I would like to find all unique strings in my JavaScript project. 我想在我的JavaScript项目中找到所有唯一的字符串。 I'm using WebStorm to search for it and I have this in terms of my search: 我正在使用WebStorm进行搜索,而我的搜索条件如下:

'.*' // any number of quoted characters

This does get me all the strings in the project but I would like to exclude some and am not sure how to. 这确实使我获得了项目中的所有字符串,但是我想排除一些字符串,但不确定如何做。

I get results like import s and require s which I would like to exclude: 我得到类似import的结果,并require我要排除的结果:

const _ = require('lodash');
and
import React from 'react';

What could I enter for a search to exclude that from my results? 我可以输入什么来将搜索结果排除在搜索范围之外?

尝试这样的否定前瞻(?!require)(?!import)('.*') ,它似乎产生了我想要的结果

I don't think the regex you posted in your answer (?!require)(?!import)('.*') works: 我认为您在答案(?!require)(?!import)('.*')发布的正则表达式不起作用:

 const tests = [ "const _ = require('lodash');", "import React from 'react';", "some other 'string'" ]; tests.forEach(test => { console.log(/(?!require)(?!import)('.*')/.test(test)); }); 

Negative lookbehind works: 负向后看的作品:

 const tests = [ "const _ = require('lodash');", "import React from 'react';", "some other 'string'" ]; tests.forEach(test => { console.log(/(?<!(require|import).*)'.+'/.test(test)); }); 

Caveat: I believe negative lookbehind is currently only supported in Chrome 警告:我认为目前仅Chrome支持负向后看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式在两个字符串之间查找字符串,不包括外部字符串 - Regex to find string between two strings, excluding outer strings 在字符串中查找所有匹配的正则表达式模式和匹配索引 - Find all matching regex patterns and index of the match in the string 正则表达式找到所有以=开头的字符串并以&结尾 - regex find all the strings preceded by = and ending in & 正则表达式匹配除分隔符之外的所有内容 - Regex match all excluding a delimiter 使用 JS 或 JQUERY 构建正确的正则表达式的问题:仅在一行中替换 2 个字符串之间的所有模式 - Problem to build the right Regex with JS or JQUERY: replace all patterns between 2 strings in only one line 在 javascript 中使用正则表达式来查找所有出现但不包括特定字符串的所有事件 - Using Regex in javascript to find all occurrance all up to but excluding the particular string 使用 javascript 中的多个正则表达式模式匹配字符串 - Match strings with multiple regex patterns in javascript JavaScript Regex无限循环的某些模式 - JavaScript Regex Infinite Loop on Some Patterns 正则表达式找到独特的单词 - RegEx find unique words 正则表达式 - 查找所有以 $_ 开头且位于模板字符串之间任意位置的单词 - Regex - find all words starting with $_ that fall anywhere between template strings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM