Jump to content

Regular Expression


aspnetguy

Recommended Posts

Hi,Could someone be kind enough to give me a regular expression for the following situation and a brief explaination. I am having a tough time with this one.I need ot remove anything between [? and ?]sometimes it will be [?text1?] or it could be [?menu1 type="horizontal" showName="false"?]Any help is appreciated

Link to comment
Share on other sites

I just read some tutorial on regular expressions... I think this might do the trick:

\[\?.+\?\]

I just read it, so I might be wrong :) .

Link to comment
Share on other sites

Here it is, use the Explode Function to split the string into an array.

<?php $myString = '[?menu1 type="horizontal" showName="false"?]'; print "<p>string to check: <b>$myString</b></p>";$explodedString = explode('[?', $myString, 2); $firstBit=$explodedString[1];$secondBit = explode('?]', $firstBit, 2);print "<p>Outcome: <b>$secondBit[0]</b></p>";?>

Link to comment
Share on other sites

thanks guys...I figured it out
/\[\?.*\?\]/

Just from curiosity, what does the "/" do?[edit]Ah, I see[/edit] Edited by boen_robot
Link to comment
Share on other sites

  • 2 weeks later...

Or in || or in "" :) lol Doesn't really matter. Be carefull with the quotes, if there are any slashes or forward slashes in the expression and it is not enclosed by one of the delimiters, the expression would fail :)So always enclose in "//" or "||" would do fine :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...