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

I am trying to search for a variation of a string in large bodies of text. The string is IPv6, which is presented in many different ways (i.e. ipv6, IPv6, IPV6, ip v6, IP v6, IP V6...etc). What is a better way to search for this than:
$string =~ m/ipv6|IPv6|ip v6|IP v6| IP V6/ ...etc

Replies are listed 'Best First'.
Re: RegEx help
by tilly (Archbishop) on Dec 22, 2008 at 09:19 UTC
    /ip\s*v6/i
Re: RegEx help
by gone2015 (Deacon) on Dec 22, 2008 at 10:01 UTC

    Or:

    $string =~ m/\bip\s*v6\b/i
    which will look for it separated from other stuff by something which would not match '\w' (where the start and end of the string are deemed not to match '\w'). This will not match 'hip v6' or 'ip v61' or 'ipv6_1' (the last because '_' will match '\w'). It will match 'ip v6.12' -- but only up to (but not including) the '.'.

Re: RegEx help
by Anonymous Monk on Dec 22, 2008 at 09:42 UTC
    old school
    /[iI][pP]\s*[vV]6/
    IP UP We all P
Re: RegEx help
by imrags (Monk) on Dec 22, 2008 at 10:12 UTC
    Use $str =~ /^ip\s*v6/i
    Raghu

      That will only match for the beginning of the string and will not find any occurences in the rest of the string.

      As I understand the original request, the anchor ^ is not wanted here.

        Yup..sorry for that ^
        Raghu