January 24th, 2012, 06:45 AM
Simple regular expression
In my string '$string', I want to replace every instance of ". [A-Z]",
i.e., a full stop, followed by a space, followed by a capital later
but I'm such a numpty when it comes to regular expressions.
Edit: Oops, I wonder if some good-natured soul would be so kind as to move my thread to the regex forum 'which we now have'!!!
Last edited by cafelatte; January 24th, 2012 at 07:31 AM.
January 24th, 2012, 09:31 AM
Done. Thanks for noticing.
Use $1 to insert the letter back into the replacement string, since that's the only variable part of the whole thing.
January 24th, 2012, 12:56 PM
I'd suggest one tiny change from Requinix's suggestion because you want to match a literal period, not a "dot" (any character).
I have tested this php.
Period. Again.One.Word. Hi.5.33
$string='Period. Again.One.Word. Hi.5.33';
echo htmlentities(preg_replace($regex,'.<br /><br />\1',$string));
Period.<br /><br />Again.One.Word.<br /><br />Hi.5.33
The htmlentities is just for display, what you want is the preg_replace.
Let us know if one of those works for you.
Last edited by ragax; January 27th, 2012 at 09:32 PM.
Reason: Inserted space char in the regex