正则表达式将一个词大写

时间:2014-02-19 09:13:59

标签: regex

我一直在解决来自不同来源的正则表达式问题。你能帮助我解决这个问题的正则表达式吗

Use substitution to replace every occurrence of the word i with the word I (uppercase, I as in me). E.g.: i'm replacing it. am i not? -> I'm replacing it. am I not?. A regex match is replaced with the text in the sub field when using substitution.

我试过这个正则表达式

.*\bi|.*i$

但是存在此错误You are not replacing i at the end of the string.。 BTW regex101是练习正则表达式问题的好地方。

1 个答案:

答案 0 :(得分:2)

你的正则表达应该是......

\bi\b
带有g标志的

\bword boundary,有助于匹配单个字词。

g标志将匹配所有此类出现而不是匹配一次。