[英]Need a regex to match a single character or word but should not match substrings
I have the following sample text: 我有以下示例文本:
I want to replace all instances of ;
我想替换所有的实例;
, :
, ,
, .
, :
, ,
, .
, and
, a
, an
, the
with pipe |
, and
, a
, an
, the
与管|
symbol. 符号。
So the output should be something like: 所以输出应该是这样的:
I tried with the following regex but i am not getting a generic regex which matches for all: 我尝试使用以下正则表达式,但未获得与所有匹配的通用正则表达式:
"\/(^|\\W);($|\\W)\/",
"\/(^|\\W):($|\\W)\/",
"\/(^|\\W),($|\\W)\/",
"\/(^|\\W).($|\\W)\/",
"\/(^|\\W)and($|\\W)\/",
"\/(^|\\W)a($|\\W)\/",
"\/(^|\\W)an($|\\W)\/",
"\/(^|\\W)the($|\\W)\/",
"\/(^|\\W)said($|\\W)\/",
Also tried: 还尝试了:
(?<=\s)(;.)
(?<=\s)(:.)
(?<=\s)(,.)
(?<=\s)(..)
(?<=\s)(an.)
(?<=\s)(and.)
But does not work, please help. 但是不起作用,请帮忙。 Please note a search for a
should match the portion 请注意,搜索的a
应与该部分匹配
with a light emitting 有发光
but should not match 但不匹配
extraction 萃取
. 。 Similar behavior required for others. 其他人也需要类似的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.