Jump to content

Regex Multiple Return MAtches


themodem

Recommended Posts

Hi all, I have a regex which gets me the following info

Titles & Actions

 

'/((?:{module title\="((?:[a-zA-Z0-9_ ]*))" action\="((?:[a-zA-Z0-9_ ]*))"\}))/i'

 

So if I enter {module title="Galleries" action="frontlist"} I get back.

 

Galleries & frontlist.

 

This is working fine but I cant work out how to get multiple paramaters back, for example if I have the following string

 

{module title="Contact" action="getform" form="contact"}

 

How would i get back  the form part as a match. This could change dynamicly like

 

{module title="Contact" action="getform" form="contact" anotherParamater="Foo" yetAnother="Bar"}

 

Thanks

Link to comment
Share on other sites

one option would be to add to the pattern to match any number of non-end-brace characters so that it matches up until the end of the braced section:

 

'/((?:{module title\="((?:[a-zA-Z0-9_ ]*))" action\="((?:[a-zA-Z0-9_ ]*))"[^}]*\}))/i'

 

i'm not a regex guru, so you might need to escape that end brace in the character set i've added.

 

EDIT: wasn't paying close enough attention. see JAY's post.

Link to comment
Share on other sites

Excelent, I have changed it slightly to

 

'/{module ([^"]+)="([^"]+)" ([^"]+)="([^"]+)" ([^"]+)="([^"]+)"[^}]*}/i'

 

This returns

 

Array
(
    [0] => Array
        (
            [0] => {module title="Contact" action="getform" form="contact" another="test"}
        )

    [1] => Array
        (
            [0] => title
        )

    [2] => Array
        (
            [0] => Contact
        )

    [3] => Array
        (
            [0] => action
        )

    [4] => Array
        (
            [0] => getform
        )

    [5] => Array
        (
            [0] => form
        )

    [6] => Array
        (
            [0] => contact
        )

)

 

As the paramater field changes.

 

Thanks all for your help.

Link to comment
Share on other sites

Ive worked out a better way for me to do my tags however i now have a new query for you all :)

 

I now have tags like {block="header"} and {block="image" src="test"}

 

I can get regex to match {block="header"} and src="test"} but not the whole thing. For example

 

Using the regex /(?<tag>{?(?<params>(?<paramName>[a-zA-Z0-9]+)\="(?<paramValue>[a-zA-Z0-9-_ ]+)")+}?)/

 

I get the following

 

Array
(
    [0] => Array
        (
            [0] => class="yellowbar"
            [1] => id="header"
            [2] => id="eyebrowNav"
            [3] => title="topMenu"
            [4] => id="navigation"
            [5] => title="mainMenu"
            [6] => class="nyroModal"
            [7] => class="frontLeft"
            [8] => class="breaker"
            [9] => class="nyroModal"
            [10] => class="frontRight"
            [11] => class="breaker"
            [12] => class="nyroModal"
            [13] => class="frontLeft"
            [14] => class="breaker"
            [15] => id="footer"
            [16] => title="bottomMenu"
        )

    [1] => Array
        (
            [0] => class="yellowbar"
            [1] => id="header"
            [2] => id="eyebrowNav"
            [3] => title="topMenu"
            [4] => id="navigation"
            [5] => title="mainMenu"
            [6] => class="nyroModal"
            [7] => class="frontLeft"
            [8] => class="breaker"
            [9] => class="nyroModal"
            [10] => class="frontRight"
            [11] => class="breaker"
            [12] => class="nyroModal"
            [13] => class="frontLeft"
            [14] => class="breaker"
            [15] => id="footer"
            [16] => title="bottomMenu"
        )

    [2] => Array
        (
            [0] => class
            [1] => id
            [2] => id
            [3] => title
            [4] => id
            [5] => title
            [6] => class
            [7] => class
            [8] => class
            [9] => class
            [10] => class
            [11] => class
            [12] => class
            [13] => class
            [14] => class
            [15] => id
            [16] => title
        )

    [3] => Array
        (
            [0] => yellowbar
            [1] => header
            [2] => eyebrowNav
            [3] => topMenu
            [4] => navigation
            [5] => mainMenu
            [6] => nyroModal
            [7] => frontLeft
            [8] => breaker
            [9] => nyroModal
            [10] => frontRight
            [11] => breaker
            [12] => nyroModal
            [13] => frontLeft
            [14] => breaker
            [15] => footer
            [16] => bottomMenu
        )

)

 

Which is matching the html aswell as the {} tags.

 

What im looking for is something that will match

 

{ID="VALUE" MULTIPLE TIMES UNTILL} is found

 

With {DATA} being a group and all sub groups in it, if that makes any sense :)

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.