Community
    • Login

    How to change apostrophe to letter g as a whole word

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 910 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Mohamed MohamedM Offline
      Mohamed Mohamed
      last edited by

      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.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @Mohamed Mohamed
        last edited by

        @Mohamed-Mohamed ,

        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 ⇒ a0a95fae-4d8b-4aea-adfd-f4f05f27c03b-image.png

        First, the \b means “word boundary”, and somethin' and breakin' do not have a “word boundary” between the h or k and the in; in fact, if anything, you want a “not a word boundary” before the in, so it would be \B(in) instead.

        Second, \z matches the end of the file, so unless the in' to ing 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 match in anywhere, rather than being restricted to the end of a word
        • (in)(?<!g) ⇒ not quite what you want, because that would match the in in brink
          • and why use a lookbehind at the end of a sequence? It doesn’t do what you think. It says “match i then n, then in the next character position, make sure that a g does not come before”. So in the word something, you would match the i and then the n, then the cursor is between n and g and it looks backwards and says “the character before (that is, the n you just matched) is not a g, so I am fine”. 153c7955-2c0c-42d2-bcaf-48525e1eb16d-image.png
          • I think what you intended was a negative lookahead instead: (?!g) b24898f6-fbe6-45cd-8d96-ac1cbc80845e-image.png
          • 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 a g in that same character location.

        Closer to what you want is \B(in)' … which will work on all the examples above… but that has a problem: it will match Karin'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

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        Mohamed MohamedM 1 Reply Last reply Reply Quote 3
        • Mohamed MohamedM Offline
          Mohamed Mohamed @PeterJones
          last edited by

          @PeterJones Thank you, it works

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors