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?

Use the lazy operator, the question mark:

"#\[b\](.*?)\[/b\]#"
// hashes make better delimiters when you're using slashes
commented: great help +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.