0

Here's sample lines I'm working with:

<br/>
About Company Name<br/>
<p>This is just some random text About nothing.</p>
<br/>

Basically I want to manipulate any line that begins with About and ends with <br/>.

I just want to bold it like this: <b>About Company Name</b><br/>

I can find that text like this:

^About.*<br/>

But I can't figure out how to add the bold symbols. Any help would be appreciated.

1
  • Maybe just preg_replace('~^(About.*)(<br\s*/>\s*)$~m', '<p>$1</p>$2', $s). Commented Apr 22, 2016 at 22:25

1 Answer 1

2

Add a capture group to your regex like this:

^(About.*)<br\/>$

And then use the regex like this:

$s = preg_replace('/^(About.*)<br\/>$/m', '<b>$1</b><br/>', $s);

Regex101 Tested

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.