Find and Replace using regular expression



  • 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 !



  • @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.



  • @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.



  • 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 :)



  • Imgur


Log in to reply