Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Find and Replace using regular expression

    Help wanted · · · – – – · · ·
    2
    5
    1352
    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.
    • ConteudoAnimal com br
      ConteudoAnimal com br last edited by

      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 !

      Scott Sumner 2 Replies Last reply Reply Quote 1
      • Scott Sumner
        Scott Sumner @ConteudoAnimal com br last edited by Scott Sumner

        @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
        • Scott Sumner
          Scott Sumner @ConteudoAnimal com br last edited by Scott Sumner

          @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
          • ConteudoAnimal com br
            ConteudoAnimal com br last edited by

            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
            • Scott Sumner
              Scott Sumner last edited by

              Imgur

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              Copyright © 2014 NodeBB Forums | Contributors