Regex/pregmatch question?

Tigratrus

Well-known member
Can anyone help me nail down the syntax for a preg_match to pull the BBCode out of the raw post content in the DB field?

It's gotta be pretty close to:

preg_match('/\[img(=(.*?))?\](.*?)\[\/img\]/', $subject, $results);

At least I *think* so, I'm not even vaguely a regexian ;).

Any help would be greatly appreciated!

James
 

Tigratrus

Well-known member

Wait... Suddenly remembered that Jaxel is doing this in XenPorta.

preg_match('#\[img\](.+?)\[/img\]#i', $post['message'], $matches)

Aha! :) Thx Jaxel!

James
 

Jaxel

Well-known member
Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems.
Regular Expressions are BAD!
 

sifuhall

Active member
Could I use this to replace multiple line breaks with a single line break?

I'm thinking the match pattern would be something like:

\r\n\r\n|\n\n|\r\r

And the replacement would be

\n

Would this work?
 

Jaxel

Well-known member
I would use this:
Code:
$post['message'] = preg_replace('#\n{2,}#', "\n", trim($post['message']));
This would search for instances of 2 or more \n tags and replace it with \n... you could also use \r\n if you needed it, but on my forum \n works better.
 
Top