[thelist] regexp question

John Pye john.pye at purplehouse.com
Thu Mar 29 10:43:54 CST 2001


Hi Sam

To count your repeated characters, as far as I know you can only specify
matches by the number of repeats - which would mean you would need to know
how many repeats you seek:

/.{3,5}/

would match 3,4, or 5 of any character in a row

/(-{3,5}|_{3,4})/

would match either 3,4,5 dashes or 3,4 underscores

perhaps your best bet is just to match

/.+/ and count the length of the matched pattern returned.

Newlines aren't included in the '.' wildcard because rege3xps aren't really
designed to span lines except by explicit reference to linebreaks with \n (I
could be wrong there I guess)

Hope that helps

John Pye
http://www.creativebase.com/
+44 (0)20 7258 6900


-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Sam-I-Am
Sent: Thursday, March 29, 2001 5:05 PM
To: evolt list
Subject: [thelist] regexp question


I'm trying to match repeated characters. And capture how many times they
are repeated.
e.g given string '--------_____' I want to know that there are 8 '-'
characters, followed by 5 '_' characters.
I even seem to recall this being one of the first examples in on of
o'reilly's perl books... but can't find it now.

I've been trying variations on this theme
/(.)+/	# which *I* read as any single character repeatd 1+ times (but
the regexp engine reads as any number of any characters except newline

/(.)+\1/ # again, I read this as any single character repeated 1+ times,
followed by any character except the one I first matched...

anyway, so none of this works as expected (surprise! isn't that the joy
of regexp :)
Anyone have a clue??

thanks
Sam

---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !







More information about the thelist mailing list