I would like to find all unique strings in my JavaScript project. I'm using WebStorm to search for it and I have this in terms of my search:
'.*' // 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:
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.