NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Search/Replace with Regexp


Joined: 08 Sep 2012
Posts: 2
Reply with quote
Hello, I searched the forums but I couldn't find any recent discussions on this. I have the latest version of PHPed for Windows 7

I would like to search and replace with regular expressions and newline characters, etc. like this:

Code:

Text:
FOOBAR
FOOBAZ

Search for:
FOO(.+)

Replace with:
FOO\n\t$1

Expected result:
FOO
   BAR
FOO
   BAZ


This is something I used to do all the time 6 years ago when I was using Zend 5. It looks like regexp variables and special characters in the "replace" box might not be supported. Will this ever be implemented?
View user's profileFind all posts by DMackSend private message
Guru master

Joined: 24 Jul 2009
Posts: 724
Reply with quote
I could never find a metacharacter that would work for \t or \n in the replacement string, but there is another way.

Tick multiline search/replace and regular expression. Then search for FOO(.+) and replace with FOO<enter><tab>\1 but press the Enter key where I show <enter> and Tab key for <tab>

Where you are in multiline mode, those Enter and Tab characters will be entered directly into text. Bear in mind that if the PhpED editor is not set to Use tab character then a tab will be entered into the editor window as spaces.
View user's profileFind all posts by plugnplaySend private message


Joined: 08 Sep 2012
Posts: 2
Reply with quote
Ah! I was used to using $1, $2... for regexp variables, I wouldn't have thought to try \1, \2...
That will help immensely! I guess I can use several regexp/nonregexp search and replace oparations to accomplish what I want, just not all in one go. Now that I know I can do variables, that really helps. Thanks, plugnplay
View user's profileFind all posts by DMackSend private message


Joined: 23 Sep 2012
Posts: 1
Reply with quote
I thought I can do variables! Thanks for this one!
View user's profileFind all posts by lynashSend private message
Search/Replace with Regexp
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic