Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need a regex for matching repeating lines of symbols (example: ------------- or *****************)

Tags:

regex

php

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?

like image 925
Haroldo Avatar asked Oct 14 '22 06:10

Haroldo


1 Answers

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.

like image 57
codaddict Avatar answered Nov 03 '22 00:11

codaddict