regexr.string
Regular expressions for humans
Predefined patterns:
START = Raw("^", entire=True)
START_OF_STRING = Raw(r"\A", entire=True)
END = Raw("$", entire=True)
END_OF_STRING = Raw(r"\Z", entire=True)
NUMBER = DIGIT = Raw(r"\d", entire=True)
NUMBERS = DIGITS = Raw(r"\d+", entire=True)
MAYBE_NUMBERS = MAYBE_DIGITS = Raw(r"\d*", entire=True)
NON_NUMBER = NON_DIGIT = Raw(r"\D", entire=True)
WORD = Raw(r"\w", entire=True)
WORDS = Raw(r"\w+", entire=True)
MAYBE_WORDS = Raw(r"\w*", entire=True)
NON_WORD = Raw(r"\W", entire=True)
WORD_BOUNDARY = Raw(r"\b", entire=True)
NON_WORD_BOUNDARY = Raw(r"\B", entire=True)
WHITESPACE = Raw(r"\s", entire=True)
WHITESPACES = Raw(r"\s+", entire=True)
MAYBE_WHITESPACES = Raw(r"\s*", entire=True)
NON_WHITESPACE = Raw(r"\S", entire=True)
SPACE = Raw(" ", entire=True)
SPACES = Raw(" +", entire=True)
MAYBE_SPACES = Raw(" *", entire=True)
TAB = Raw(r"\t", entire=True)
DOT = Raw(r"\.", entire=True)
ANYCHAR = Raw(".", entire=True)
ANYCHARS = Raw(".+", entire=True)
MAYBE_ANYCHARS = Raw(".*", entire=True)
LETTER = Raw("[a-zA-Z]", entire=True)
LETTERS = Raw("[a-zA-Z]+", entire=True)
MAYBE_LETTERS = Raw("[a-zA-Z]*", entire=True)
LOWERCASE = Raw("[a-z]", entire=True)
LOWERCASES = Raw("[a-z]+", entire=True)
MAYBE_LOWERCASES = Raw("[a-z]*", entire=True)
UPPERCASE = Raw("[A-Z]", entire=True)
UPPERCASES = Raw("[A-Z]+", entire=True)
MAYBE_UPPERCASES = Raw("[A-Z]*", entire=True)
ALNUM = Raw("[a-zA-Z0-9]", entire=True)
ALNUMS = Raw("[a-zA-Z0-9]+", entire=True)
MAYBE_ALNUMS = Raw("[a-zA-Z0-9]*", entire=True)
Segment
— Segments of a regular expression</>CharClass
— Used to indicat a set of characters wrapped by[]
</>OneOfChars
— Positive character set[...]
</>NoneOfChars
— Negative character set[^...]
</>Look
— Look ahead or behind</>LookAhead
— Look ahead(?=...)
</>LookBehind
— Look behind(?<=...)
</>LookAheadNot
— Look ahead not(?!...)
</>LookBehindNot
— Look behind not(?<!...)
</>Quantifier
(
*args
,lazy
,capture
,flags
,deflags
)
— Quantifier+
,*
,?
,{m}
or{m,n}
</>ZeroOrMore
—*
zero or more times</>OneOrMore
—+
one or more times</>Maybe
—?
zero or one times</>Repeat
— Match fromm
ton
repetitions{m,n}
or{m,}
</>RepeatExact
— Match exactm
repetitions{m}
</>Lazy
— Non-greedy modifier+?
,*?
,??
,{m,}?
or{m,n}?
</>Flag
— Flag(?aiLmsux)
</>InlineFlag
— Inline flag(?aiLmsux-imsx:...)
</>Raw
— Raw strings without escaping</>Or
—|
connected segments</>Capture
— Capture a match(...)
</>NonCapture
— Non-capturing grouping(?:...)
</>Concat
— Concatenate segments</>Conditional
—(?(...)yes|no)
conditional pattern</>Captured
—(?P=name)
captured group or \1, \2, ...</>Regexr
(Regexr) — The entrance of the package to compose a regular expression</>
regexr.string.
Segment
(
*args
, capture=False
, flags=None
, deflags=None
)
Segments of a regular expression
ClassVars:
NONCAPTURING_WRAPPING: Whether we should wrap the segment with brackets
when capture
is False
.
In some cases, for example, (abc)+
is already an entire group, it
won't confuse the parser when it comes with other segments, such as
(abc)+d
. We don't need an extra brackets to separate it from other
segments. However, we need brackets for other segments, such as
a|b|c
, because a|b|cd
will confuse the parser. In such a case,
we need (?:a|b|c)d
if we don't need to capture the segment.
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.args
— Another segments to be wrapped by this one.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
CharClass
(
*args
, capture=False
, flags=None
, deflags=None
)
Used to indicat a set of characters wrapped by []
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
OneOfChars
(
*args
, capture=False
, flags=None
, deflags=None
)
Positive character set [...]
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
NoneOfChars
(
*args
, capture=False
, flags=None
, deflags=None
)
Negative character set [^...]
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Look
(
*args
, capture=False
, flags=None
, deflags=None
)
Look ahead or behind
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
LookAhead
(
*args
, capture=False
, flags=None
, deflags=None
)
Look ahead (?=...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
LookBehind
(
*args
, capture=False
, flags=None
, deflags=None
)
Look behind (?<=...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
LookAheadNot
(
*args
, capture=False
, flags=None
, deflags=None
)
Look ahead not (?!...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
LookBehindNot
(
*args
, capture=False
, flags=None
, deflags=None
)
Look behind not (?<!...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Quantifier
(
*args
, lazy=False
, capture=False
, flags=None
, deflags=None
)
Quantifier +
, *
, ?
, {m}
or {m,n}
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
ZeroOrMore
(
*args
, lazy=False
, capture=False
, flags=None
, deflags=None
)
*
zero or more times
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
OneOrMore
(
*args
, lazy=False
, capture=False
, flags=None
, deflags=None
)
+
one or more times
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Maybe
(
*args
, lazy=False
, capture=False
, flags=None
, deflags=None
)
?
zero or one times
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Repeat
(
*args
, m
, n=None
, lazy=False
, capture=False
, flags=None
, deflags=None
)
Match from m
to n
repetitions {m,n}
or {m,}
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
RepeatExact
(
*args
, m
, lazy=False
, capture=False
, flags=None
, deflags=None
)
Match exact m
repetitions {m}
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Lazy
(
*args
, capture=False
, flags=None
, deflags=None
)
Non-greedy modifier +?
, *?
, ??
, {m,}?
or {m,n}?
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Flag
(
*args
)
Flag (?aiLmsux)
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
InlineFlag
(
*args
, capture=False
, flags=None
, deflags=None
)
Inline flag (?aiLmsux-imsx:...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Raw
(
*args
, capture=False
, entire=False
, flags=None
, deflags=None
)
Raw strings without escaping
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Or
(
*args
, capture=False
, flags=None
, deflags=None
)
|
connected segments
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Capture
(
*args
, name=None
, capture=None
, flags=None
, deflags=None
)
Capture a match (...)
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
NonCapture
(
*args
, flags=None
, deflags=None
)
Non-capturing grouping (?:...)
flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Concat
(
*args
, capture=False
, flags=None
, deflags=None
)
Concatenate segments
capture
(bool | str, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Conditional
(
id_or_name
, yes
, no=None
, capture=False
, flags=None
, deflags=None
)
(?(...)yes|no)
conditional pattern
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Captured
(
id_or_name
, capture=False
, flags=None
, deflags=None
)
(?P=name)
captured group or \1, \2, ...
capture
(bool, optional) — The name of the capture, False to disable capturing andTrue to capture without name.flags
(int | str | Sequence[int | str], optional) — The flags to be used when compiling this segment.deflags
(int | str | Sequence[int | str], optional) — Remove the flags fromre.compile()
while compilingthis segment.
pretty
(
indent
, level
)
→ str
Pretty print this segment, depending on capture
indent
(str) — The indent string.level
(int) — The indent level.
__str__
(
)
String representation of this segment, depending oncapture
The final string representation of this segment.
regexr.string.
Regexr
(
*segments
)
→ Regexr
The entrance of the package to compose a regular expression
It is actually a subclass of str
, but with an extra method compile
,
which compiles the regular expression and returns a re.Pattern
object.
*segments
(Segment or str) — The segments of the regular expression.When composing the regular expression, the segments are concatenated
compile
(
flags=0
)
→ Pattern
Compile the regular expression and return a re.Pattern
object
See also re.compile()
flags
(int, optional) — The flags to be used when compiling the regular expression.
pretty
(
indent=' '
)
→ str
Pretty print the regular expression
__repr__
(
)
→ str
String representation of this regular expression