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

A regex of the type (...)* doesn't work if the expected match starts later than position 0 #836

Closed
p6rt opened this issue Mar 25, 2009 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Mar 25, 2009

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

Searchable as RT64188$

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

From @masak

<masak> rakudo​: +("freeeeeeeeeeeeeeeew" ~~ /('e'|'w')*/)[0]
<p6eval> rakudo 9a84c3​: OUTPUT«Use of uninitialized value␤»
<masak> <TimToady> that oughta work...
<masak> did someone report this?
<masak> rakudo​: +("eeeeeeeeeeeeeeeew" ~~ /('e'|'w')*/)[0]
<p6eval> rakudo 9a84c3​: RESULT«17»
* masak submits rakudobug

The first piece of code should evaluate to 17 as well, IMO. The regex
was later simplified to /(e)*/ with the same outcome.

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

From @moritz

On Wed Mar 25 02​:57​:13 2009, masak wrote​:

<masak> rakudo​: +("freeeeeeeeeeeeeeeew" ~~ /('e'|'w')*/)[0]
<p6eval> rakudo 9a84c3​: OUTPUT«Use of uninitialized value␤»
<masak> <TimToady> that oughta work...
<masak> did someone report this?
<masak> rakudo​: +("eeeeeeeeeeeeeeeew" ~~ /('e'|'w')*/)[0]
<p6eval> rakudo 9a84c3​: RESULT«17»
* masak submits rakudobug

The first piece of code should evaluate to 17 as well, IMO. The regex
was later simplified to /(e)*/ with the same outcome.

It does work as designed. It matches the zero repetition (and thus empty
string)

15​:53 < moritz_> rakudo​: ?("freeeeeeeeeeeeeeeew" ~~ /('e'|'w')*/)
15​:53 < p6eval> rakudo 9a84c3​: RESULT«Bool​::True»

And since it matched the parenthesis group zero times, $/[0] is the
empty list.

If you want to match at least once, use +.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

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

@p6rt
Copy link
Author

p6rt commented Mar 25, 2009

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

@p6rt p6rt closed this as completed Mar 25, 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