PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Jul 22, 2017 11:45 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Aug 17, 2015 8:00 am 
Offline
Forum Newbie

Joined: Mon Aug 17, 2015 7:53 am
Posts: 1
I am beginner with regex, tried to make regex for this problem but coulndt,
I need a single regex to replace multiple words: 111, 222, 333, in text like this with 444, 555, 666 (case insensitive):

Example:
randomtext111randomtext
randomtext222
randomtext
333randomtext
randomtext

To replace with words 444, 555, 666 to have this result:

randomtext444randomtext
randomtext555
randomtext
666randomtext
randomtext

I managed to replace when every word is in single line, with this in powergrep:

(111)
(222)
(333)

replace with

444
555
666

but it doesnt work in above example.


Top
 Profile  
 
PostPosted: Mon Aug 17, 2015 4:07 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6457
Location: WA, USA
You won't be able to use a single regex to do three different replacements. It has to be three separate ones.

Side note: if the words are as simple as just "111" then you don't need (shouldn't use) regular expressions - simple find-and-replace functions like str_replace() are perfectly fine. And you can give all three replacements at once too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 7 guests


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 post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group