mIRC Home    About    Download    Register    News    Help

Print Thread
#197501 07/04/08 10:15 AM
Joined: Jan 2008
Posts: 22
D
dassa Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2008
Posts: 22
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.


dassa #197502 07/04/08 11:01 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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!


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #197505 07/04/08 11:48 AM
Joined: Jan 2008
Posts: 22
D
dassa Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2008
Posts: 22
Hi Jaytea,
Thanks for your reply. Yes if it would not be too much to ask i would love an explanation

dassa #197508 07/04/08 01:22 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Link Copied to Clipboard