When people are posting some text on my website, they will sometimes insert a long line of hyphens, asterisks or full-stops like this
*********************************************************************
That will unfortunately destroy the layout on some result pages, and it’s kind of pointless (to me).
How should I handle this? Maybe a regex that will reduce more than X repeats of the same character to only 5. If so, then how…
Regex regex = new Regex("[\\*\\._-]{5,}");
string goodstring = regex.Replace(badstring, "-----");
But what if a user thought it was fun to write aaaaaaaaaaaaaaaaaaaaaaaaaa, then my regex would fail.
The question is. How do you think I should handle this problem and if you think I should handle it with a regex, then how do I write a regex that would remove unnecessary repeats of any character (and not just *.-_ like my own regex here)?
To answer your regular expression question:
You can use a backreference to detect the same character entered more than once, for example:
However the main point of your question seems to be this:
You should use stylesheets to specify what should happen when the text doesn’t fit into its container. For example, you can use the overflow property to set the content to hide or scroll on overflow, rather than having the default behaviour which is that overflowing content can overlap other elements on the page.