• Login
Community
  • Login

Find and Replace using regular expression

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 2 Posters 1.7k 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.
  • C
    ConteudoAnimal com br
    last edited by Dec 12, 2018, 8:00 PM

    Hello people,

    I have a question

    I’m using regular expression to find and replace

    on search : ^case “/[a-Z0-9].php" (fine)
    on replace: ^case "/[a-Z0-9]
    .php”: (issue)

    It finds no issue but it replace incorrect

    It finds case “/123.php” and replace to ^case “/[a-Z0-9]*.php”: and not case “/123.php”: as I expected :-((

    Thanks in advance for any help …

    thanks a lot !

    S 2 Replies Last reply Dec 12, 2018, 8:09 PM Reply Quote 1
    • S
      Scott Sumner @ConteudoAnimal com br
      last edited by Scott Sumner Dec 12, 2018, 8:11 PM Dec 12, 2018, 8:09 PM

      @ConteudoAnimal-com-br

      Ugh. See the italics in your expressions? You have * in there that are being consumed by this site. Put your regular expressions inside a pair of grave accents: `like this` so we can see what you really mean (the grave accents will keep this site from messing with special characters). Examine what you are composing in the Preview pane and if it doesn’t match what you intend, keep revising until it does before pressing Submit.

      1 Reply Last reply Reply Quote 1
      • S
        Scott Sumner @ConteudoAnimal com br
        last edited by Scott Sumner Dec 12, 2018, 8:29 PM Dec 12, 2018, 8:28 PM

        @ConteudoAnimal-com-br

        So as I said without proper formatting it is hard to tell, but I think this line gives us a clue:

        It finds case “/123.php” and replace to ^case “/[a-Z0-9]*.php”: and not case “/123.php”
        

        You need to use a capture group–using parenthesis–in the find part and then refer to the group in the replace part (by number).

        So maybe:

        Find what: ^case "/(\w+)\.php"
        Replace with: ^case "/\1.php":

        I made some other tweaks, hopefully I am interpreting your need correctly.

        1 Reply Last reply Reply Quote 3
        • C
          ConteudoAnimal com br
          last edited by Dec 12, 2018, 8:48 PM

          Scott

          Thanks a lot … worked perfect …

          I learnt I need to put a sentence and left next blank to not get italics … sorry it was my first post on forum :)

          1 Reply Last reply Reply Quote 2
          • S
            Scott Sumner
            last edited by Dec 12, 2018, 8:53 PM

            Imgur

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