[英]How to regex for two words before and after specified string?
I am using node.js and reading string for matching 我正在使用node.js并读取字符串以进行匹配
</em><em>
The same string used in regex 正则表达式中使用的相同字符串
var regex=new RegEx('<\/em><em>',"g");
I want to get two words before and after the matched string. 我想在匹配的字符串之前和之后得到两个词。
E.g.,
abc233 3344</em><em>abcd 3333
3333abcd 3444</em><em>3333 dkdkd
Any one assist me? 有人帮我吗?
Thanks in advance. 提前致谢。
You can use following regex : 您可以使用以下正则表达式:
/((?: |^)\w+){2}<\/em><em>(\w+(?: |$)){2}/gm
See demo https://regex101.com/r/fY2qE3/1 参见演示https://regex101.com/r/fY2qE3/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.