Yii Framework Forum: Need little regex help - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need little regex help how to escape "/>" ?? Rate Topic: -----

#1 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 537
  • Joined: 21-June 10

Posted 18 February 2011 - 06:47 AM

Hello everyone,

I am creating a template parser function that can recognise some tag like this
<wl:include param1="value1" param2="value2" param3="value3" />

currently I am using this regex to match...
$regex = '#<wl:include\ (([a-zA-Z0-9]*)=(.*))*\/>#iU';


it's quite working but unfortunately it can't read this tag
<wl:include param1="value1" param2="value2" param3="some tag with <br/> like this" />
it will only read until :
<wl:include param1="value1" param2="value2" param3="some tag with <br/>

How do I fix the regex.. I am still learning regex so maybe I miss something...
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#2 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 915
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 18 February 2011 - 06:53 AM

try this one, didn't test but should work
'#<wl:include\ (\w*)=(\'\")?([^\'\"]*))*(\'\")? \/>#iU'


in the param it checks for quotes and will end after the quotes
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#3 User is offline   jpenguin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 16-February 11

Posted 18 February 2011 - 06:55 AM

try add the end of line symbol $ ?

$regex = '#<wl:include\ (([a-zA-Z0-9]*)=(.*))*\/>$#iU';

0

#4 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 537
  • Joined: 21-June 10

Posted 18 February 2011 - 09:07 AM

@Gustavo
Wow, what a quick reply :D
I've tried but unfortunately it doesn't work

@Jpenguin
Thanks.. I'll try it later..
currently not on my working laptop :)
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#5 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 537
  • Joined: 21-June 10

Posted 19 February 2011 - 02:00 AM

unfortunately adding $ still doesn't solve it...
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#6 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 537
  • Joined: 21-June 10

Posted 19 February 2011 - 02:10 AM

After some trial and error I think I've solve my problem. The regex I've made is like this:
$regex = '#<wl:include\ ([\w]*=[\"\'](.*)[\"\'])*[\ ]*\/>#iU';


Thanks for everybody's help
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users