aspnetguy Posted May 13, 2006 Share Posted May 13, 2006 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 More sharing options...
boen_robot Posted May 13, 2006 Share Posted May 13, 2006 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 More sharing options...
scott100 Posted May 13, 2006 Share Posted May 13, 2006 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 More sharing options...
aspnetguy Posted May 13, 2006 Author Share Posted May 13, 2006 thanks guys...I figured it out /\[\?.*\?\]/ Link to comment Share on other sites More sharing options...
boen_robot Posted May 13, 2006 Share Posted May 13, 2006 (edited) thanks guys...I figured it out/\[\?.*\?\]/ Just from curiosity, what does the "/" do?[edit]Ah, I see[/edit] Edited May 13, 2006 by boen_robot Link to comment Share on other sites More sharing options...
aspnetguy Posted May 13, 2006 Author Share Posted May 13, 2006 Just from curiosity, what does the "/" do?<{POST_SNAPBACK}> the expression must be enclosed in // Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 23, 2006 Share Posted May 23, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now