alecramsay / REmake

A high-level language for building regular expressions (RE)
MIT License
0 stars 0 forks source link

Add mode modifiers #1

Closed alecramsay closed 1 year ago

alecramsay commented 1 year ago

Example 2.1c

alecramsay commented 1 year ago

One possibility is:

Add 'with' (<list-of-mode-modifiers>) { ... }

another is toggling modes on & off.

alecramsay commented 1 year ago

See P. 65

alecramsay commented 1 year ago

Modifiers:

For example:

(?i-sm: ...)

-or- the inline variations:

(?i)
(?-i)
(?s)
(?-s)
(?m)
(?-m)
(?x)
(?-x)

Re: Python support

alecramsay commented 1 year ago

Python re. Flags.

(?aiLmsux-imsx:...)

(Zero or more letters from the set 'a', 'i', 'L', 'm', 's', 'u', 'x', optionally followed by '-' followed by one or more letters from the 'i', 'm', 's', 'x'.) The letters set or remove the corresponding flags: [re.A](https://docs.python.org/3/library/re.html#re.A) (ASCII-only matching), [re.I](https://docs.python.org/3/library/re.html#re.I) (ignore case), [re.L](https://docs.python.org/3/library/re.html#re.L) (locale dependent), [re.M](https://docs.python.org/3/library/re.html#re.M) (multi-line), [re.S](https://docs.python.org/3/library/re.html#re.S) (dot matches all), re.U (Unicode matching), and [re.X](https://docs.python.org/3/library/re.html#re.X) (verbose), for the part of the expression. (The flags are described in [Module Contents](https://docs.python.org/3/library/re.html#contents-of-module-re).)

The letters 'a', 'L' and 'u' are mutually exclusive when used as inline flags, so they can’t be combined or follow '-'. Instead, when one of them appears in an inline group, it overrides the matching mode in the enclosing group. In Unicode patterns (?a:...) switches to ASCII-only matching, and (?u:...) switches to Unicode matching (default). In byte pattern (?L:...) switches to locale depending matching, and (?a:...) switches to ASCII-only matching (default). This override is only in effect for the narrow inline group, and the original matching mode is restored outside of the group.

New in version 3.6.

Changed in version 3.7: The letters 'a', 'L' and 'u' also can be used in a group.
alecramsay commented 1 year ago

Use in Python