How to change apostrophe to letter g as a whole word
-
Is it possible to change word ending “in’” to “ing” for example “something” and “breaking”? Somethin’ to something.
I used Gemini and they gave me
\b(in )'\z \b(in')'\z \b(in)\z \b(in)(?<!g)\z
But all didn’t work.
-
But all didn’t work.
Of course not. None of those correctly described the circumstances you wanted.
Looking at https://npp-user-manual.org/docs/searching/#anchors for the definitions of the sequences at the beginning and end of all those attempts ⇒
First, the
\b
means “word boundary”, andsomethin'
andbreakin'
do not have a “word boundary” between theh
ork
and thein
; in fact, if anything, you want a “not a word boundary” before thein
, so it would be\B(in)
instead.Second,
\z
matches the end of the file, so unless thein'
toing
is at the very end of your file, there is no way any of those will work.Ignoring the incorrect
\b
and\z
placement in all those expressions:(in )'
⇒ requires a space before the apostrophe, which I doubt you want(in')'
⇒ requires two apostrophes (one that you want to keep and one you want to throw away), which is not what you claimed you wanted(in)
⇒ will matchin
anywhere, rather than being restricted to the end of a word(in)(?<!g)
⇒ not quite what you want, because that would match thein
inbrink
- and why use a lookbehind at the end of a sequence? It doesn’t do what you think. It says “match
i
thenn
, then in the next character position, make sure that ag
does not come before”. So in the wordsomething
, you would match thei
and then then
, then the cursor is betweenn
andg
and it looks backwards and says “the character before (that is, then
you just matched) is not ag
, so I am fine”. - I think what you intended was a negative lookahead instead:
(?!g)
- but if you use the apostrophe, which is required for what you were describing anyway, you don’t need the negative lookahead for the
g
at all, because matching an apostrophe will obviously not match ag
in that same character location.
- and why use a lookbehind at the end of a sequence? It doesn’t do what you think. It says “match
Closer to what you want is
\B(in)'
… which will work on all the examples above… but that has a problem: it will matchKarin's
, which you probably don’t want. So then add a negative lookahead for a word character – so it will allow punctuation or space or newline or EOF after the apostrophe, but not alphanumeric.Final result:
\B(in)'(?!\w)
----
Useful References
-
@PeterJones Thank you, it works