Goose Posted June 17, 2007 Share Posted June 17, 2007 I know there are resources on Google and here on this site for this topic, but I don't know what it is actually called so I don't know what to search for. So hopefully some of you smart people can help me out. I am doing a regular expressions search and I want to find a bbcode like tag. There is only one tag and its opening tag looks like [ail] and its closing tag looks like [/ail]. I want to replace the opening and closing tags and have been doing that easily with str_replace() but now I need to do more than replace text. I want to grab the text inside the tags with a regular expression. So, how do I match this pattern [ail]inside_text[/ail] and store the inside_text into a variable? Thanks! Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/ Share on other sites More sharing options...
Henaro Posted June 18, 2007 Share Posted June 18, 2007 You mean BBcode? Can I refer you to this post? http://www.phpfreaks.com/forums/index.php/topic,145449.0.html Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/#findComment-276632 Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 That does help ... but the thing that I would like to know how to do is take the regex result $1 and save it to php variable that I can use outside the regex. Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/#findComment-276990 Share on other sites More sharing options...
Wildbug Posted June 18, 2007 Share Posted June 18, 2007 If you don't want to replace anything, use preg_match_all(). The parenthetical expressions will be captured in an array. Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/#findComment-277062 Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 I am doing this now by using the preg_match function first and then replacing the matches later using preg_replace. Seems to work fine. Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/#findComment-277064 Share on other sites More sharing options...
Goose Posted June 18, 2007 Author Share Posted June 18, 2007 I was writing my reply as you were submitting yours Wildbug, thanks for the tips though! Link to comment https://forums.phpfreaks.com/topic/55981-solved-regex-matches-help/#findComment-277070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.