Dennis
Dennis

Reputation: 714

regex: put sentence into paragraph tags

hi I have a lot of sentences I want convert them into paragraphs (split sentences by dot). How can I make it with regex?

sample:

"MBB Industries AG: Veröffentlichung gemäß § 26 Abs. 1 WpHG mit dem Ziel der europaweiten Verbreitung MBB Industries AG 09.07.2014 16:48 Veröffentlichung einer Stimmrechtsmitteilung, übermittelt durch die DGAP - ein Unternehmen der EQS Group AG. Für den Inhalt der Mitteilung ist der Emittent verantwortlich."

I want this (there is a date inside - pay attention):

<p>MBB Industries AG: Veröffentlichung gemäß § 26 Abs.</p><p>1 WpHG mit dem Ziel der europaweiten Verbreitung MBB Industries AG 09.07.2014 16:48 Veröffentlichung einer Stimmrechtsmitteilung, übermittelt durch die DGAP - ein Unternehmen der EQS Group AG.</p><p>Für den Inhalt der Mitteilung ist der Emittent verantwortlich.</p>

I am able to make this with php use explode -> foreach -> add <p> tags.

but I want be able make it with regex. thanks.

Upvotes: 0

Views: 71

Answers (2)

Toto
Toto

Reputation: 91488

How about:

$str = "MBB Industries AG: Veröffentlichung gemäß § 26 Abs. 1 WpHG mit dem Ziel der europaweiten Verbreitung MBB Industries AG 09.07.2014 16:48 Veröffentlichung einer Stimmrechtsmitteilung, übermittelt durch die DGAP - ein Unternehmen der EQS Group AG. Für den Inhalt der Mitteilung ist der Emittent verantwortlich.";
$str = '<p>' . preg_replace('/(?<!\d)\.(?!\d)/', '.</p><p>', $str) . '</p>';
echo $str,"\n";

output:

<p>MBB Industries AG: Veröffentlichung gemäß § 26 Abs.</p><p> 1 WpHG mit dem Ziel der europaweiten Verbreitung MBB Industries AG 09.07.2014 16:48 Veröffentlichung einer Stimmrechtsmitteilung, übermittelt durch die DGAP - ein Unternehmen der EQS Group AG.</p><p> Für den Inhalt der Mitteilung ist der Emittent verantwortlich.</p><p></p>

Upvotes: 1

adam.baker
adam.baker

Reputation: 1485

For the middle,

Replace: (\.[ ]+)
With: </p><p>

Then for the beginning:

Replace: ^"
With: <p>

And the end:

Replace: "$
With: </p>

Upvotes: 2

Related Questions