I'll see if I can explain what the regular expression does. Firstly, the 'm' flag on the end is the "multiline" flag. It helps the re match when there are multiple lines (i.e. carriage returns and/or linefeeds) in the string.
Now for the regular expression itself: [tt]/((.)|(\r\n))\1{2,}/[/tt]
[tt]/([!](.)[/!]|(\r\n))\1{2,}/[/tt] The dot is the metacharacter to match ANY one character. The parens around it save the character matched for later reference.
[tt]/((.)|[!](\r\n)[/!])\1{2,}/[/tt] Matches a carriage return followed by a line feed (which is how DOS-type files encode a new line), and the parens save the match for later reference.
[tt]/[!]([/!](.)[!]|[/!](\r\n)[!])[/!]\1{2,}/[/tt] The vertical bar '|' is an "OR", so this matches either the single character OR the new line. The parens around this group it for later reference.
[tt]/((.)|(\r\n))[!]\1[/!]{2,}/[/tt] This is a
backreference. It returns the value of the FIRST (counting from innermost and leftmost sets of parens) saved match (remember I said we were saving the matched value for later reference). Since we have an OR of two possible values wrapped in parens, the \1 will return either the single character matched, or the CrLf.
[tt]/((.)|(\r\n))\1[!]{2,}[/!]/[/tt] The part is a "quantifier". It says to find the previous match
a minimum of two times. There is no maxiumum number of times given, so it will eat up the entire repeated set.
So what we now have is "any character or a CrLf, followed by that SAME character or CrLf two or more times. In other words, three or more occurences of any single character or CrLf combination.
I believe you can find out WHICH character is repeated by using RegExp property $1, but you might have to use match instead of test for that.
Tracy Dryden
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
![[dragon] [dragon] [dragon]](/data/assets/smilies/dragon.gif)