0

I have been solving regex problems from different sources. Can you guys help me to figure how the regex for this problem

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.

I tried with this regex

.*\bi|.*i$

But there is this error You are not replacing i at the end of the string.. BTW regex101 is a great site to practice regex problems.

ntstha
  • 1,187
  • 4
  • 23
  • 41

1 Answers1

2

Your regex should be.....

\bi\b

with g flag

\b is a word boundary that helps match individual words.

g flag would match all such occurances instead of matching once.

Community
  • 1
  • 1
Anirudha
  • 32,393
  • 7
  • 68
  • 89