Ok so I am trying to create some BB code from scratch, and my big problem is the \S and \s and .* are very greedy. For example, when I try to use bb code on something like this:

$text = "[b]abcdefg[/b] !@#$%^&* [b]0123456789[/b]";
$text = preg_replace("/\[b\](.*)\[\/b\]/","<b>\\1</b>",$text);
//same thing:
//$text = preg_replace("/\[b\]([\s\S]+)\[\/b\]/","<b>\\1</b>",$text);
echo $text;

i get my output to look like this:
abcdefg{/b} !@#$%^&*() {b}0123456789
without the { } around the bold markers (I put them there because i didn't know how to tell daniweb to print it out as a literal). But now what I want it to look like is this:
abcdefg !@#$%^&* 0123456789
where the text in the middle is not bold

I know what I have to do to get fix this, but I don't know how to implement it, what is should be is {b} then any text except for another {b} and then end on a {/b} I some how have to put a carat ^ in there but dont know how to do it in this example

can anyone help?

11 Years
Discussion Span
Last Post by Ooble

Use the lazy operator, the question mark:

// hashes make better delimiters when you're using slashes
great help
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.