[英]Javascript regex pattern match multiple strings ( AND, OR, NEAR/n, P/n )
I need to filter a collection of strings based on a rather complex query I have query input as a string 我需要基于一个相当复杂的查询来过滤字符串集合,我将查询输入作为字符串
var query1 ='Abbott near/10 (assay* OR test* ) AND BLOOD near/10 (Point P/1 Care)';
From this query INPUT string I want to collect just the important words: 从这个查询输入字符串中,我只想收集重要的单词:
var words= 'Abbott assay* test* BLOOD Point care';
The query can change for example: 查询可以更改,例如:
var query2='(assay* OR test* OR analy* OR array) OR (Abbott p/1 Point P/1 Care)';
from this query need to collect 从这个查询中需要收集
var words='assay* test* analy* array Abbott Point Care';
I'm looking for your suggestion. 我正在寻找您的建议。
Thanks. 谢谢。
You may just use |
您可以使用|
in your regex to capture the words and/or special characters that you want to remove: 在正则表达式中捕获要删除的单词和/或特殊字符:
([()]|AND|OR|(NEAR|P)\/\d+) ?
DEMO: https://regex101.com/r/rqpmXr/2 演示: https : //regex101.com/r/rqpmXr/2
Note the /gi
in the regex options, with i
meaning that it's case insensitive. 注意regex选项中的/gi
,其中i
表示不区分大小写。
EXPLANATION: 说明:
([()]|AND|OR|(NEAR|P)\\/\\d+)
- This is a capture group containing all the words you specified in your title, plus the parentheses. ([()]|AND|OR|(NEAR|P)\\/\\d+)
-这是一个捕获组,其中包含您在标题中指定的所有单词以及括号。 (NEAR|P)\\/\\d+
- Just to clear out this part, \\d+
means that one or more digits are following the words NEAR
or P
. (NEAR|P)\\/\\d+
-为了清除这一部分, \\d+
表示单词NEAR
或P
之后是一个或多个数字。 ?
- This captures the possible trailing space after the captured word. -这将捕获捕获的单词之后的可能的尾随空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.