phemal has asked for the wisdom of the Perl Monks concerning the following question:

Suppose i have string containing both "[SYN]" and "[SYN, ACK]" patterns. can someone help me writing a patern matching for the above.

i tried /\bstring\b/ but both pattern have square brackets and hence not able to find a suitable match.

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: pattern matching for string [SYN, ACK]
by davido (Cardinal) on Sep 14, 2006 at 04:39 UTC

    Are you looking for this?

    m/\[SYN(?:, ACK)?\]/

    What are you actually trying to accomplish?


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: pattern matching for string [SYN, ACK]
by GrandFather (Saint) on Sep 14, 2006 at 04:39 UTC

    Which of the following strings ought match:

    [SYN] [syn] [Syn] [SYN, ACK] [SYN] [SYN, ACK] [ACK] SYN SYN, ACK ACK

    What pattern did you try specifically? The following pattern may be what you want:

    /\[SYN(?:, ACK)?\]/

    Update: couple more test strings added


    DWIM is Perl's answer to Gödel