Community
    • Login

    Using Regex for special search and replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 592 Views
    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.
    • Jorge García LópezJ
      Jorge García López
      last edited by

      Sorry for my english. It’s not my mother tongue.

      Let’s say I have a text like the following

      Lorem ipsum dolor sit amet, consectetur adipiscing elit. ~Praesent~ condimentum, ligula et egestas pretium, magna nunc tincidunt mauris, at fermentum ~massa~ enim ut mi. Ut ac faucibus lacus. Donec vel est ~et~ justo posuere vulputate. Donec viverra id neque eget vehicula. Donec luctus pharetra odio vitae fringilla. Integer dictum hendrerit congue. ~Pellentesque~ maximus fermentum nulla sed pulvinar. Nulla nisi lorem, interdum ~non~ sagittis nec, posuere a massa. ~Sed~ vitae ex ac ~eros~ dapibus iaculis. Sed ~sit~ amet augue eu justo ultricies facilisis. Pellentesque rhoncus ipsum ligula, at rhoncus mi sollicitudin in.

      NOTE: Some words are delimited with ~ like ~non~

      I know I can find words using regex for example using: ~[A-Z][A-Z][A-Z]~

      But I have trouble when trying to replace them.

      For example i would find ~Sed~ and ~non~

      Then when replacing lines all become $[A-Z][A-Z][A-Z]&
      and I would like to have $Sed& and $non&

      Because when I do all become the same word.

      Question 1:
      Would it be possible to find them regardless the character number. Find ~Praesent~ and ~sed~

      At the moment i use ~[A-Z][A-Z][A-Z]~ then i find words with 3 characters

      Question 2:
      How can I replace only the beging and ending of this words. By this I mean changing
      ~sed~ for \textbf{sed}
      ~Praesent~ for \textbf{Praesent}

      Is this possible?

      Thank you very much.

      Jorge

      Meta ChuhM 1 Reply Last reply Reply Quote 1
      • Meta ChuhM
        Meta Chuh moderator @Jorge García López
        last edited by Meta Chuh

        hola y bienvenido a la notepad++ community, @Jorge-García-López

        yes this is possible.

        find what: ~(.*?)~
        replace with: \\textbf{$1}
        search mode: regular expression
        wrap around: enabled

        then hit replace all

        this will change this text:

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. ~Praesent~ condimentum, ligula et egestas pretium, magna nunc tincidunt mauris, at fermentum ~massa~ enim ut mi. Ut ac faucibus lacus. Donec vel est ~et~ justo posuere vulputate. Donec viverra id neque eget vehicula. Donec luctus pharetra odio vitae fringilla. Integer dictum hendrerit congue. ~Pellentesque~ maximus fermentum nulla sed pulvinar. Nulla nisi lorem, interdum ~non~ sagittis nec, posuere a massa. ~Sed~ vitae ex ac ~eros~ dapibus iaculis. Sed ~sit~ amet augue eu justo ultricies facilisis. Pellentesque rhoncus ipsum ligula, at rhoncus mi sollicitudin in.

        to this:

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. \textbf{Praesent} condimentum, ligula et egestas pretium, magna nunc tincidunt mauris, at fermentum \textbf{massa} enim ut mi. Ut ac faucibus lacus. Donec vel est \textbf{et} justo posuere vulputate. Donec viverra id neque eget vehicula. Donec luctus pharetra odio vitae fringilla. Integer dictum hendrerit congue. \textbf{Pellentesque} maximus fermentum nulla sed pulvinar. Nulla nisi lorem, interdum \textbf{non} sagittis nec, posuere a massa. \textbf{Sed} vitae ex ac \textbf{eros} dapibus iaculis. Sed \textbf{sit} amet augue eu justo ultricies facilisis. Pellentesque rhoncus ipsum ligula, at rhoncus mi sollicitudin in.

        1 Reply Last reply Reply Quote 3
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors