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 howto example in "Lookahead Assertions" #69703

Closed
Pavel mannequin opened this issue Oct 30, 2015 · 5 comments
Closed

regex howto example in "Lookahead Assertions" #69703

Pavel mannequin opened this issue Oct 30, 2015 · 5 comments
Labels
docs Documentation in the Doc dir topic-regex type-bug An unexpected behavior, bug, or error

Comments

@Pavel
Copy link
Mannequin

Pavel mannequin commented Oct 30, 2015

BPO 25517
Nosy @akuchling, @birkenfeld, @ezio-melotti, @serhiy-storchaka, @elenaoat
Files
  • issue25517.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-01-11.22:12:26.221>
    created_at = <Date 2015-10-30.10:07:26.641>
    labels = ['expert-regex', 'type-bug', 'docs']
    title = 'regex howto example in "Lookahead Assertions"'
    updated_at = <Date 2016-01-11.22:12:26.220>
    user = 'https://bugs.python.org/Pavel'

    bugs.python.org fields:

    activity = <Date 2016-01-11.22:12:26.220>
    actor = 'ezio.melotti'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2016-01-11.22:12:26.221>
    closer = 'ezio.melotti'
    components = ['Documentation', 'Regular Expressions']
    creation = <Date 2015-10-30.10:07:26.641>
    creator = 'Pavel'
    dependencies = []
    files = ['41566']
    hgrepos = []
    issue_num = 25517
    keywords = ['patch']
    message_count = 5.0
    messages = ['253725', '253726', '257906', '258032', '258033']
    nosy_count = 9.0
    nosy_names = ['akuchling', 'georg.brandl', 'ezio.melotti', 'mrabarnett', 'docs@python', 'python-dev', 'serhiy.storchaka', 'Elena.Oat', 'Pavel']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25517'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @Pavel
    Copy link
    Mannequin Author

    Pavel mannequin commented Oct 30, 2015

    The example advises ".*..*$" expression "to match filenames where the extension is not bat". But here is an example which passes such check:

    >>> re.match("(.*)[.](?!bat$).*$", "test.a.bat")
    <_sre.SRE_Match object at 0x7ff221996f30>

    To my mind use of negative lookbehind expressions (not covered so far in the HOWTO) is better:

    >> re.match("(.*)[.].*(?<!.bat)$", "test.a.bat")
    >>

    @Pavel Pavel mannequin assigned docspython Oct 30, 2015
    @Pavel Pavel mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Oct 30, 2015
    @serhiy-storchaka
    Copy link
    Member

    Note that lookbehind assertions still are not documented in Regular Expression HOWTO.

    The example that demonstrates negative lookahead assertion is ".*.[^.]$". But then we should explain why ".*" is changed to "[^.]".

    @elenaoat
    Copy link
    Mannequin

    elenaoat mannequin commented Jan 10, 2016

    Corrected the regular expression and documented why [^.]* is used.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 11, 2016

    New changeset c6b5c03183e3 by Ezio Melotti in branch '2.7':
    bpo-25517: fix regex in the regex howto. Patch by Elena Oat.
    https://hg.python.org/cpython/rev/c6b5c03183e3

    New changeset 6bd4a4907f66 by Ezio Melotti in branch '3.5':
    bpo-25517: fix regex in the regex howto. Patch by Elena Oat.
    https://hg.python.org/cpython/rev/6bd4a4907f66

    New changeset 48e2f5915d49 by Ezio Melotti in branch 'default':
    bpo-25517: merge with 3.5.
    https://hg.python.org/cpython/rev/48e2f5915d49

    @ezio-melotti
    Copy link
    Member

    Fixed, thanks for the patch!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir topic-regex type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants