mIRC Homepage
Posted By: dassa regex help - 07/04/08 10:15 AM
Greetings
I need a regex that will return true if there are more then ten consecutive characters in a string. For example the string in red below will return true

"Hi this string willlllllllll return true"

I also need a regex if a string has ten or more the same tokens anywhere in a string. For example the string in red below will return true

"this string will return will true will will this string will will will will will true will hi will"

as the string above has ten the word will in it, it will (excuse the pun) return true.

I am aware that this may be able to be done in other ways like $findtok etc. but i do think a cleverly written regex will be more efficient.

Posted By: jaytea Re: regex help - 07/04/08 11:01 AM
for the first you can simply use:

Code:
/(.)\1{10}/i



you could add a + next to the ., (.+), if you want it to match a repeated string of any length. such as "lalalalalalalalalalala"

the second regex is a bit longer:

Code:
/(?:^| )([^ ]++)(?:.* \1(?= |$)){9}/i


a variation of this would be to match not necessarily space delimited words, just any series of word characters (\w), as in "bla.hi.bla.bla.bla.loool.bla.bla.bla.bla.ipswitch.bla.bla"

Code:
/\b(\w++)(?:.+\b\1\b){9}/i


if you need an explanation of how these work, just ask!
Posted By: dassa Re: regex help - 07/04/08 11:48 AM
Hi Jaytea,
Thanks for your reply. Yes if it would not be too much to ask i would love an explanation
Posted By: jaytea Re: regex help - 07/04/08 01:22 PM
well, would be great if you could tell me your current regex abilities.. do you understand the syntax i've used or have you not begun to learn it yet? if you haven't then i suggest you make your way through some tutorial, such as the one on http://www.regular-expressions.info . read, experiment and become comfortable with the basics and what you see above. then i'd be happy to explain how they work if you still can't figure them out

explaining them to someone without at least a little familiarity with regex would be a waste of time, you need to learn the fundamentals ;P
© mIRC Discussion Forums