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 !
-
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. -
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 :)
-

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