SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem with Perl regular expression pattern matching

    I'm very new to Perl programming and am having trouble creating a regular expression for pattern matching. I want to pattern match a specific text string followed by a certain number of any combination of letters and digits.

    For example, in some text, I want to search for the text "Bob: " and then let's say the next 20 characters, which can be any combination of alphas and numerics. How would I construct that regex match?

    Thanks in advance for your help!

  2. #2
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Wait.

    You want to find "Bob:" and then *capture* the next 20 or so characters?

    I mean, there's always [0-9a-zA-Z]{20} for 20 alpha and numeric characters, but I suspect that's not what you mean.

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that is exactly what he means. Here is syntax that makes it easy to extract the match:

    my $string = "Bob: 1234567890AbCdEfGhIj";

    my ($alpha_num_string) = $string =~ /Bob: [A-Za-z0-9]{20}/;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •