Pattern bug matching whitespace in multi-line match? 
Author Message
 Pattern bug matching whitespace in multi-line match?

The code below, when executed, indicates that the multi-line string $_
matches white-space pattern /^\s*$/ when multi-line matching is enabled,
even though $_ contains non-white-space characters. Am I overlooking
something, or is this a bug?

###############################################################
#!/usr/bin/perl
#  Demonstrate possible bug in regular expressions

$* = 1;  # Multi-line search
$_ = "

  Hello
";

/^\s*$/ && print "String: '$_' \n matches whitespace pattern /^\\s*\$/.\n";

################################################################

Here is the version of Perl installed at my site:

$RCSfile: perl.c,v $$Revision: 4.0.1.7 $$Date: 92/06/08 14:50:39 $
Patch level: 35

--
     Mark



Wed, 01 Nov 1995 06:47:00 GMT  
 Pattern bug matching whitespace in multi-line match?
: The code below, when executed, indicates that the multi-line string $_
: matches white-space pattern /^\s*$/ when multi-line matching is enabled,
: even though $_ contains non-white-space characters. Am I overlooking
: something, or is this a bug?

Setting $* means that ^ and $ can match in the middle of the string, and
not just at the ends.  So your pattern will match any empty line within
your string.  It doesn't have to match your whole string.

Larry



Wed, 01 Nov 1995 18:36:55 GMT  
 Pattern bug matching whitespace in multi-line match?

Quote:


>: The code below, when executed, indicates that the multi-line string $_
>: matches white-space pattern /^\s*$/ when multi-line matching is enabled,
>: even though $_ contains non-white-space characters. Am I overlooking
>: something, or is this a bug?
>Setting $* means that ^ and $ can match in the middle of the string, and
>not just at the ends.  So your pattern will match any empty line within
>your string.  It doesn't have to match your whole string.

I guess this means there's no way to match the begining or end of the
string in multiple-line mode (maybe Perl 5 should have ^^ and $$ r.e.
operators??); but (he says in a flash of inspiration) one can see if
$` and/or $' are empty to see if there is anything left unmatched
before/after the matched section...

--
Michael A Stoodt  [MaS]      |       mumble mumble disclaimer mumble...

Comp&InfoSci, UMassDartmouth | "Weird Al" Yankovic, _Dare To Be Stupid_



Mon, 06 Nov 1995 22:53:08 GMT  
 Pattern bug matching whitespace in multi-line match?

:

: >: The code below, when executed, indicates that the multi-line string $_
: >: matches white-space pattern /^\s*$/ when multi-line matching is enabled,
: >: even though $_ contains non-white-space characters. Am I overlooking
: >: something, or is this a bug?
:
: >Setting $* means that ^ and $ can match in the middle of the string, and
: >not just at the ends.  So your pattern will match any empty line within
: >your string.  It doesn't have to match your whole string.
:
: I guess this means there's no way to match the begining or end of the
: string in multiple-line mode (maybe Perl 5 should have ^^ and $$ r.e.
: operators??); but (he says in a flash of inspiration) one can see if
: $` and/or $' are empty to see if there is anything left unmatched
: before/after the matched section...

Alternately and/or alternatively, you can refrain from setting $*,
leaving ^ and $ to match the beginning and end of the string, and then
match on explicit \n in the middle.

Larry



Wed, 08 Nov 1995 06:23:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. bug in anchored, multiline pattern match

2. regex to match a multi line pattern

3. Multi line pattern matches?

4. Multi-line pattern matching?

5. pattern matching in multi-line strings fails under perl4.034

6. regex to match a multi line pattern

7. Multi-line pattern matching

8. Multi line pattern match

9. Can't Match Multi-Line Pattern

10. Multiline pattern matching with command line invocation

11. Multi-line pattern matching in 5.001n

12. multiline, multi pattern match

 

 
Powered by phpBB® Forum Software