• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Regex/pregmatch question?

Tigratrus

Well-known member
#1
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
#2

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

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

Aha! :) Thx Jaxel!

James
 

sifuhall

Active member
#7
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
#8
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.