pattern match

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mamoon
    New Member
    • Sep 2006
    • 18

    #1

    pattern match

    hello,
    i have a string(SADFDSFD SFLLSDFKFDLKFKL FDDSFLKDSKS) or something like this.
    and i have a pattern (AL???LW) of five characters where ? is any one out of the sixteen alphabets given.
    i have to search this pattern in the string.
    language=perl
    platform=linux( 32 bit i686).
    if anyone of u can help, plz help.
    waiting
    mamoon
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Questions and notes:

    1) Instead of a fake string, why not just tell us the real thing. That would enable us to get a more realistic feel for what you're doing.
    2) Your pattern is actually 7 characters long, but you state it's "five characters"
    3) "where ? is any one out of the sixteen alphabets given" - What does this mean? What is a one sixteen alphabets given? Do you mean that there are specific alphanumeric characters that fit into match those question marks? Say A through P (yes that's 16 characters).

    Anyway, all those questions aside, here is a basic example that might help:

    Code:
    my $string = "SADFDSFDSFLLSDFKFDLKFKLFDDSFLKDSKS";
    if ($string =~ m/(SD\w{3}DL)/) {
       print "Match is $1";
       # Outputs SDFKFDL
    }
    For a first step to learning about regular expressions, start here:

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      I'm usually able to figure out questions, even poorly worded ones. But I have no idea what you are asking.

      Comment

      • tpgames
        Contributor
        • Jan 2007
        • 783

        #4
        Originally posted by mamoon
        hello,
        i have a string(SADFDSFD SFLLSDFKFDLKFKL FDDSFLKDSKS) or something like this.
        and i have a pattern (AL???LW) of five characters where ? is any one out of the sixteen alphabets given.
        i have to search this pattern in the string.
        language=perl
        platform=linux( 32 bit i686).
        if anyone of u can help, plz help.
        waiting
        mamoon
        It sounds like a game. Okay, what is being asked, I think is:
        Given a certain string, and a certain pattern, find this pattern in the string. I hope this helps. And, I think he does mean 5 = # of characters in pattern. ? = one of 16 alphabets. Key, however, is not the 16 alphabets. Instead, its match the pattern in the string.

        (I'd right an answer but I've only just begun to study Perl last August, and have not had time to look at it since.)

        Comment

        Working...