Skip to content

Introduce a method to concatenate regex patterns #77839

Open

Description

@aleskva
mannequin
BPO 33658
Nosy @ezio-melotti, @serhiy-storchaka

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 = None
created_at = <Date 2018-05-27.08:53:27.253>
labels = ['expert-regex', 'type-feature', '3.7']
title = 'Introduce a method to concatenate regex patterns'
updated_at = <Date 2018-05-28.08:16:03.689>
user = 'https://bugs.python.org/aleskva'

bugs.python.org fields:

activity = <Date 2018-05-28.08:16:03.689>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Regular Expressions']
creation = <Date 2018-05-27.08:53:27.253>
creator = 'aleskva'
dependencies = []
files = []
hgrepos = []
issue_num = 33658
keywords = []
message_count = 2.0
messages = ['317787', '317829']
nosy_count = 5.0
nosy_names = ['ezio.melotti', 'mrabarnett', 'THRlWiTi', 'serhiy.storchaka', 'aleskva']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue33658'
versions = ['Python 3.7']

Activity

  1. aleskva commented on May 27, 2018

    aleskvamannequin
    MannequinAuthor

    After removing inline flags (deprecated in https://bugs.python.org/issue22493) piping patterns will not work:
    pats = [r'(?m)^line.continues$', r'(?s)begin.*?end']
    re.compile('|'.join(pats))

    Maybe there should be introduced some method to merge patterns (similar to re.escape)?

  2. serhiy-storchaka commented on May 28, 2018

    @serhiy-storchaka
    Member

    This is not trivial task because inline flags with global scope can be occurred in any part of the pattern (although using them not at the start of the pattern is deprecated).

    But starting with 3.7 you can use inline flags with local scope. This will allow you to use simple string concatenation.

    pats = [r'(?m:^line.continues$)', r'(?s:begin.*?end)']
  3. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions