Simple Markup regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Simple Markup regex

Post by Nathaniel »

So I have 3 patterns:

Code: Select all

array('/^\*([^*]+)\*$/ms', 
'/^\_([^_]+)\_$/ms', 
'/^\%([^\%]+)\%$/ms');
3 replacements:

Code: Select all

array('<strong>$1</strong>', 
'<em>$1</em>', 
'<small>$1</small>');
That gaggle of nonsense is suposed to replace *some text which needs to be bolded* with <strong>some text that needs to be bolded</strong>, etc - without running across multiple lines.

*this is valid bold markup*

*this
isn't

valid*

Instead, it doesn't replace anything. What do I need to change?

Edit: I now realize the m modifier in there isn't what I want... I need some form of "not * and not line break" regex...

- Nathaniel
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

Wow!

Code: Select all

'#\*([^*\n]+)\*#m'
is all it took!

I did try \n in there before... but I think it still didn't work because of my s modifier at the end...
Post Reply