开发者

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

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

*开发者_如何学Python***************************************************
----------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜