Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 909 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

'group' matches Perl

Thread title: 'group' matches Perl
Closed Thread    
    Thread tools Search this thread Display Modes  
02-01-2006, 04:09 PM
#1
ktsirig is offline ktsirig
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 46
iTrader: 0 / 0%
 

ktsirig is on a distinguished road

  Old  '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

02-01-2006, 04:24 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Hopefully, this will help:

Code:
while ($string =~ m/(M+)/gi) {
  print "Found '$&'";
}
The important part being m/(M+)/gi which is a regular expression matching one or more letter Ms (upper and/or lower case) together. After the last slash (/) is the global modifier (matches all instances of the M groups) and the case-insensitive modifier (take the 'i' out to make the search case-sensitive).

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed