Jun 14, 2012, 12:25 AM
Post #2 of 9
From perldoc perlre:
Re: [devi] regular expression to iggnore
[In reply to]
^ Match the beginning of the line
By default, the "^" character is guaranteed to match only the beginning
of the string, the "$" character only the end (or before the newline at
the end), and Perl does certain optimizations with the assumption that
the string contains only one line. Embedded newlines will not be matched
by "^" or "$". You may, however, wish to treat a string as a multi-line
buffer, such that the "^" will match after any newline within the string
(except if the newline is the last character in the string), and "$"
will match before any newline. At the cost of a little more overhead,
you can do this by using the /m modifier on the pattern match operator.
Hence, if the expression you want to test by regex, contains one line of your source file, you can use ^ to anchor your string at the beginning of the line.
However, I wonder why you are asking this, because you are using ^ already in the regexp you had posted.
BTW, your expression
^\s*case\s+.*?:\s*$ does not do what you claim it would do. It matches not only thos lines which have only the word case :, but would, for example, also match a line such as