# you have been shown this, but I have added another 2 digits $variable = "-----;=99;helloworld88"; $variable =~ m/(\d\d)/; print "$1\n"; # 99 -> *the first 2 digit string* in $variable will now be in $1 # Note match will stop with the first \d\d sequence looking L->R # we can get all the \d\d sequences with this regex # the key is the /g at the end which stands for global print "got a $1\n" while $variable =~ m/(\d\d)/g; #Often we might then go on to assign $1 to a variable ie my $number = $1; #You can do this in on step with the expression ($number) = $variable =~ m/(\d\d)/; print "\$number is $number\n"; # you can also capture the values of $1,$2,$3 all at once into a list $record = "John Smith 919 909 900"; ($first,$last,$phone) = $record =~ m/(\w+)\s+(\w+)\s+([\d\s]+)/; print"$first,$last,$phone\n"; # or an array @stuff = $record =~ m/(\w+)\s+(\w+)\s+([\d\s]+)/; # popped this in here for educational purposes # $" is the output record seperator,default is one space $" = ' : '; print "@stuff"; Hope this helps tachyon

In reply to Re: Reg ex question by tachyon
in thread Reg ex question by costas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.