繁体   English   中英

从字符串中提取单词的正则表达式

[英]Regular expression to extract words from string

我有一个字符串

str= "值 1 然后执行某些操作"

我需要一个正则表达式来确保 value 和 perform 出现在字符串中而不会重复。

这个简单的任务不需要正则表达式。 使用此代码

str= "value 1 then perform certain action"
var a = str.match("value") || []
var b = str.match("perform") || []
if(a.length == 1 && b.length == 1){
    console.log("true")
}else{
    console.log("false")
}

您可以按如下方式设置模式:

pattern: "value (.*) perform (.*)"

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM