开发者

How do I use RegExp Replace to replace sentence?

开发者 https://www.devze.com 2023-01-26 01:49 出处:网络
How do I use RegExp Replace to replace below word? -- (1) Replace/Remove what ever word start with \"a\" and end with \"c\"!开发者_高级运维

How do I use RegExp Replace to replace below word?

--

(1) Replace/Remove what ever word start with "a" and end with "c"!开发者_高级运维

Example (1): abc, xyz, axc, bbb, ccc ayc, a1c, abcc, axxyzc...

Replace after (1): , xyz, , bbb, ccc , , , ...

--

(2) Replace/Remove what ever word start with "abc=" and end with "&"!

Example (2): abc=123&xyz=111&abc=xgggf&abc=ffff&abc=xxxx&xyz=kkk&abc=zzz&

Replace after (2): xyz=111&xyz=kkk&

--

Thanks~~~


(1):

var replaced = string.replace(/a.*?c/gi, "");

(2):

var replaced = string.replace(/(.*?)xyz=&(.*?)/gi, "$1,$2");

The above is using Javascript. But the general regex's will be the same in all regex flavors.

0

精彩评论

暂无评论...
验证码 换一张
取 消