Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<!regex> parses but always returns true #586

Closed
p6rt opened this issue Jan 6, 2009 · 4 comments
Closed

<!regex> parses but always returns true #586

p6rt opened this issue Jan 6, 2009 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Jan 6, 2009

Migrated from rt.perl.org#62012 (status was 'rejected')

Searchable as RT62012$

@p6rt
Copy link
Author

p6rt commented Jan 6, 2009

From @finanalyst

See the following (svn revision 34915)
$ perl6

regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<digit>/ and
say 'got digit';$y~~/<!digit>/ and say 'not got digit';
got digit
not got digit
regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<!digit>/ and
say 'got digit';$y~~/<!digit>/ and say 'not got digit';
got digit
not got digit
regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<!digit>/ and
say 'got digit';$y~~/<digit>/ and say 'not got digit';
got digit

The assumption was <!digit> is the logical inverse of <digit>

Either way, /<!digit>/ is returning true with and without a digit ( $x
test in first and third lines both give 'got digit').

@p6rt
Copy link
Author

p6rt commented Jan 6, 2009

From @pmichaud

There seems to be a misunderstanding about what <!digit> does here --
it's a zero-width assertion that means "doesn't match a digit at this
point". Since your regexes are all unanchored, this assertion can be
true at many points (including the end of the string). To look at the
specific examples you give​:

On Tue Jan 06 05​:06​:46 2009, richardh wrote​:

See the following (svn revision 34915)
$ perl6

regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<digit>/ and
say 'got digit';$y~~/<!digit>/ and say 'not got digit';
got digit
not got digit

The $y match (the one calling <!digit>) succeeds at position 0, as it
should. The $x match succeeds at position 3.

regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<!digit>/ and
say 'got digit';$y~~/<!digit>/ and say 'not got digit';
got digit
not got digit

The $x match succeeds at position 0; the $y match succeeds at position 0.

regex digit { [0..9] }; my $x='abc9';my $y='def';$x~~/<!digit>/ and
say 'got digit';$y~~/<digit>/ and say 'not got digit';
got digit

The $x match succeeds at position 0. (The $y match fails.)

The assumption was <!digit> is the logical inverse of <digit>

This assumption is false -- <!digit> is the inverse of <?digit> .

I suspect what you're looking for is <-digit>, which means "match any
character that doesn't match <digit>". You'll still want to anchor the
pattern somehow, though, because "<-digit>" would've matched each of the
above cases also.

Finally, note that

  regex digit { [0..9] }

means "match a '0' followed by two characters followed by a '9'".
I suspect you meant to write

  regex digit { <[0..9]> }

So we end up with​:

regex digit { <[0..9]> }; say ("abc" ~~ /^ <-digit>* $/) ?? 'matched'
!! 'not matched'
matched
regex digit { <[0..9]> }; say ("abc9" ~~ /^ <-digit>* $/) ??
'matched' !! 'not matched'
not matched

Closing ticket,

Pm

@p6rt
Copy link
Author

p6rt commented Jan 6, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jan 6, 2009

@pmichaud - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Jan 6, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant