in reply to regular expressions help

The following will come in handy for you in the regex:
\d - a digit \w - a word character \s - whitespace.
This will allow you to put together things such as:
foreach my $line ( @lines ) { next unless $line =~ m/^\d{6} \w{3}/; # Will match '111111 aaa' where 1 is any # number, a any char. next unless $line =~ m/^\d+\s+\w+/; # Will match any number followed by any word. # The '^' anchors the search to the beginning # of the string. }

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Re: regular expressions help
by da97mld (Initiate) on Nov 06, 2003 at 09:31 UTC
      Is that supposed to be one or two square brackets? In any case, you can look for square brackets in a regex by escaping them using a '\' like: \[.

      Now you should be able to build it, have a go..

      C.

        Yep it is supposed to be one :) I've got it now. Thanks for the help. Regards, Mathias
      /[[]/ matches a single [, and /[]]/ matches a single ].

      Abigail