Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression question 1

Status
Not open for further replies.

borg2002

Programmer
Aug 7, 2002
84
0
0
US
Hello,

I have inherited a platform at work that is written in Perl by the collegue I replace. Unfortunately he is no longer here and he left no documentation whatsoever on the code he has written.
I managed to sort everything out except for this one rule:

grep /^E2EDS01.{48}011\\s*0+\\s/

I can't seem to figure out what the part {48} means.

Any help would be greatly appreciated.

Thanks
Borg
 
Hi Borg

It means 48 of the previous 'dot' i.e. 48 anythings (unless I am sadly mistaken!)

This should prove it...

Code:
@lines = ("E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011",
          "E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011",
          "E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011");

foreach $line (@lines) {
  if ($line =~ m|^E2EDS01[red].{48}[/red]011|) {
    print "match : $line\n" 
  } else {
    print "no match : $line\n";
  }
}

This gives the result:-

Code:
no match : E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011
[blue]match[/blue] : E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011
no match : E2EDS01xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx011

This is because the 1st string has only 47 characters - so no match, the 2nd has 48 and matches - and the final has 49 characters. This is too many and therefore fails to match

Hope this is of use!


Kind Regards
Duncan
 
Thanks for the answer Duncan.

I think you are right....

Thanks
Borg
 
no problem dude - I am almost certain this is the case! ;-)


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top