'group' matches? Perl

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


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Other Programming Languages

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Feb 1st, 2006, 14:57
Up'n'Coming Member
Join Date: Sep 2005
Location: athens
Age: 26
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
'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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Feb 1st, 2006, 19:48
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
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
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

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
End Time Army Youth Group thewebkid Free Web Site Critique 2 Oct 25th, 2007 04:29
Myers Communications Group Geoff Myers Free Web Site Critique 2 Apr 15th, 2007 00:09
GROUP BY and dates in SQL (again) spinal007 Databases 4 Dec 13th, 2004 17:26


All times are GMT. The time now is 04:58.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved