Simple Regexp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

Simple Regexp

Post by Walid »

Can someone help me figure out the regex to use with preg_match_all to identify all the "words" shown below (i.e. hi, bye, friend).

Code: Select all

 
Bla bla bla
{some:word=hi}
Bla bla bla
{some:word=bye}
Bla bla bla
{some:word=friend}
Bla bla bla
 
Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Simple Regexp

Post by requinix »

Here's the pattern you want to use.

Code: Select all

'/\{some:word=([^}]+)\}/i'
You can change "some:word" to anything with letters, numbers, or !@#%&-_=:;"'<,>
You can use other symbols but they must be escaped with a \ (like you do with quotes inside strings).

Now see if you can't figure the rest out yourself ;)
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

Re: Simple Regexp

Post by Walid »

Thanks. Perfect.
Post Reply