Conditional Matching
Posted: Thu Oct 01, 2009 1:47 am
The goal of my preg_replace code is this: if a line begins with a bold, italic or underline tag opener (i.e. <b> <u> <i>) OR begins with NO tag, wrap the line in a <p> tag.
This means that lines that begin with <div.., <ul>, <li>, etc will not have a paragraph tag put around them.
How can I structure the regex to match either a opening b, u, or i tag, or no tag at all?
Examples
This means that lines that begin with <div.., <ul>, <li>, etc will not have a paragraph tag put around them.
How can I structure the regex to match either a opening b, u, or i tag, or no tag at all?
Examples
Code: Select all
This is a line of text with no tags around it.
- regex will put <p> around this line
<b>this is some bold text</b>
- regex will put <p> around this line too
<li>this is a list item</li>
- regex will NOT put a <p> tag around this line