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

* operator not working correctly with sub() #106

Closed
mrabarnett opened this issue Jan 30, 2014 · 3 comments
Closed

* operator not working correctly with sub() #106

mrabarnett opened this issue Jan 30, 2014 · 3 comments
Labels
bug Something isn't working minor

Comments

@mrabarnett
Copy link
Owner

Original report by Anonymous.


>>> regex.sub('.*', 'x', 'test')
u'xx' <--- This is wrong

>>> regex.sub('.+', 'x', 'test')
u'x'

>>> re.sub('.*', 'x', 'test')
u'x' <--- This is correct

>>> regex.sub('.*?', '|', 'test')
u'|||||||||' <--- This is wrong

>>> re.sub('.*?', '|', 'test')
u'|t|e|s|t|' <--- This is correct

python 2.7 64-bit linux, compiled from source regex version 2.4.39

@mrabarnett
Copy link
Owner Author

Original comment by Anonymous.


How it should behave is a bit of a grey area.

The re module says 'x' and '|t|e|s|t|'.

Perl and PCRE says 'xx' and '|||||||||'.

This is because .* and .*? can/could match 0 characters after matching the >0 characters, and there are cases where the re module definitely gets it wrong, so it's not clear whether the re module is getting it right here.

@mrabarnett
Copy link
Owner Author

Original comment by Anonymous.


Hmm well I dont really have an opinion. The behavior of re seems intuitively correct to me, but then that may just be because I have been using re for years.

I just thought I'd report the discrepancy, as one of the goals of regex is (as I understand it) to replace re as seamlessly as possible.

@mrabarnett
Copy link
Owner Author

Original comment by Anonymous.


Fixed in regex 2014.01.30.

It now behaves more like the re module in the version 0 behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor
Projects
None yet
Development

No branches or pull requests

1 participant