正则表达式匹配并替换单词中的前缀和后缀 [英] Regex to match and replace prefix and suffix in words

查看:648
本文介绍了正则表达式匹配并替换单词中的前缀和后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我需要帮助才能制作正则表达式。

我会举例说明我想要的做。



假设考虑一句话,



这是简单的和


我想要一个正则表达式,用中的 en 替换 an

正则表达式应该只从找到一个,完整的单词应保持原样。

我也想匹配并在简单中用 ly 替换 lg



更换输出后句子将是

这只是一个结束



请帮我制作正则表达式。

提前致谢。



我的尝试:



在谷歌找不到任何这样的正则表达式

Hi friends,

I need a help in making a regular expression.
I will give a example what i am trying to do.

Suppose consider a sentence,

"This is Simplg an and"

I want a regular expression to replace an with en in word and.
Regex should find an from only and, the complete word an should remain as is.
and i also want to match and replace lg with ly in word simplg

So after replacing my output sentence will be
"This is Simply an end"

Please help me in making regex for these.
Thanks in advance.

What I have tried:

Did not find any such regex on google

推荐答案

\ban(?=d\b)

将匹配和中的an,但不是an,hand等。

will match "an" in "and", but not in "an", "hand", etc.

(?<=\bsimp)lg\b

将匹配simplg中的lg,但不会匹配lg,bulge等等。



正则表达式语言 - 快速参考 [ ^ ]

Expresso正则表达式工具 [ ^ ]

will match "lg" in "simplg", but not in "lg", "bulge", etc.

Regular Expression Language - Quick Reference[^]
Expresso Regular Expression Tool[^]


不是解决方案,但链接可能有用。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是工具的链接帮助构建RegEx并调试它们:

.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

快速正则表达式工具 [ ^ ]

这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
Not a solution, but links may be useful.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


这篇关于正则表达式匹配并替换单词中的前缀和后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆