tags:

views:

61

answers:

1

I want to be able to remove linebreaks etc that people make by using recurring characters, for example:

****************************************************
----------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

etc

i'd like to not have to specify which characters it will match, maybe all that are NOT \w characters?

also note they will not always start/end on a new line..

is this possible?

+3  A: 

For this you'll have to decide on the threshold length to decide which ones are really separators, call it N, then you can do:

$input = preg_replace('/(\W)\1{N-1,}/,'',$input);

which deletes N or more consecutive non-word char.

codaddict
$dd = preg_replace('/(\W)\1{10-1,}/i', '', $dd); doesnt seem to work even testing on http://gskinner.com/RegExr/ ?
Haroldo
I'm guessing that was pseudocode, and what he meant was `preg_replace('/(\W)\1{9,}/i', '', $dd);`. The subtraction was for you to do, not the regex parser ;)
Frank Farmer