正则表达式表示一个段落,我想在其中搜索一个单词。
我尝试使用 .search 但我没有得到正确的答案,例如:-
科学(来自拉丁语 scientia,意思是“知识”)是一项系统性的事业,它以关于宇宙的可测试的解释和预测的形式构建和组织知识。[1]具有更古老且密切相关的含义(例如,在亚里士多德中找到)
在上面的句子中,如果我必须找到“知识”这个词。我可以使用什么正则表达式。
实际上我已经在道场制作了一个表格:-
名称:文本区域 地址:文本区域 电话。否:txt 区域编号
提交按钮
现在当我点击提交按钮时。姓名、地址和电话号码字段应自动填写一个字母,如下所示:-
亲爱的[名字],
这是为了通知您等等等等。您可以联系下方签名者。 [电话号码],[地址]
- 我已经制作了表格。现在我试图匹配标签的内部 html 和括号中的单词。如果它相同,那么该值必须在字母中写入。请帮忙提供更好的想法
最佳答案
看这个:
但正如 Ollie 所指出的,这是毫无意义的。考虑到你可能想替换字符串知识,我也使用了replace函数:
var str = 'Science (from Latin scientia, meaning "knowledge") is a systematic enterprise that builds and organizes knowledge in the form of testable explanations and predictions about the universe.[1] In an older and closely related meaning (found, for example, in Aristotle)';
var match = str.match(/knowledge/gi);
if(match != null)
{
for(var i = 0; i < match.length; i++)
alert(match[i]);
var replacedString = str.replace(/knowledge/gi,'egdelwonk');
alert(replacedString);
}
根据您的编辑,请参阅我的新 jsfiddle:http://jsfiddle.net/kPRDH/
var str = 'Dear [name] ,This is to inform you that blah blah blah blah. you can contact the undersigned. [tele no] ,[address]';
str = str.replace(/\[name\]/g,'TCM');
str = str.replace(/\[tele no\]/g,'9999999999');
str = str.replace(/\[address\]/g,'221B Bakers Street');
alert(str);
关于javascript - 段落中某个单词的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12785860/