Web Design and Development Forums

'group' matches? Perl

This is a discussion on "'group' matches? Perl" within the Perl, Python, Ruby and Others section. This forum, and the thread "'group' matches? Perl are both part of the Program Your Website category.

Old Feb 1st, 2006, 14:57   #1 (permalink)
Up'n'Coming Member
 
Join Date: Sep 2005
Location: athens
Age: 25
Posts: 59
'group' matches? Perl

Hi all!

I have a string :

$seq="IIIIIMMMMMMMMMMMOOOOOOOOOOOOOOOOMMMMMMMMMMMM MIIIIIMMMMMMMMMOOOOOOOOOOOOOOMMMMMMMMMMMMMIIIMMMMM MMMMMMOOOOOOOOOOOOOOOMMMMMMMMMMMIIIIIIMMMMMMMMMMMM MOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMIIIMMMMMMMMMOOOOOOO OOOOOOOOOOOOOOOOOOOOMMMMMMMIIIIMMMMMMMMMMMOOOOOOOO OOOOOOOOOOOOOMMMMMMMIIIMMMMMMMMMOOOOOOOOOOOOOOOOOO OOOOOOOMMMMMMMMMIIIMMMMMMMMMMMOOOOOOOOOOOOOOOOOMMM MMMMMI";

and I want to find all groups of MMMMMM. I don't want to find only every position in the string that has 'M',
i.e. pos6, pos7, pos8, pos9 etc but I want to have something like:

1st group : pos 7-15
2nd group : pos 23-34
3rd group : pos 45-55

etc
ktsirig is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Feb 1st, 2006, 19:48   #2 (permalink)
Reputable Member
 
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 294
Re: 'group' matches? Perl

Code: Select all
while ($seq =~ /M+/g) {
print "From ",length($`)," to ",length($`)+length($&),"\n";
}
Gives slightly different results to yours - but I think your sample answer applies to different data as the first M is at the 6th position not the 7th as per your sample answer.

I get
Code: Select all
From 5 to 16
From 32 to 44
From 45 to 46
From 51 to 60
From 74 to 87
From 90 to 95
From 96 to 102
From 117 to 128
etc
which is counting the first character as position number 0 and is giving the first in each group and the first outside each group. I suggest adding / subtracting 1 if you want to tune this behaviour.

-- Graham
__________________
Graham Ellis ...
Open Source trainer with Well House Consultants
grahame is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
group, matches, perl

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Myers Communications Group Geoff Myers Free Web Site Critique 2 Apr 15th, 2007 00:09
Hey People, Newbie Joining the Group neel Introduce Yourself 4 Jan 8th, 2006 17:53
GROUP BY and dates in SQL (again) spinal007 MSSQL & Access 4 Dec 13th, 2004 17:26
New to the Group pahprints Introduce Yourself 8 Jun 15th, 2004 21:52



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:02.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59