All Projects → Bogdanp → Cursive_re

Bogdanp / Cursive_re

Licence: bsd-3-clause
Readable regular expressions for Python 3.6 and up.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Cursive re

kaki
Search tool designed for developers
Stars: ✭ 41 (-86.82%)
Mutual labels:  regex
Nomino
Batch rename utility for developers
Stars: ✭ 282 (-9.32%)
Mutual labels:  regex
Anyformatkit
Simple text formatting in Swift
Stars: ✭ 296 (-4.82%)
Mutual labels:  regex
truffleHog
Searches through git repositories for high entropy strings and secrets, digging deep into commit history
Stars: ✭ 6,319 (+1931.83%)
Mutual labels:  regex
Re Flex
The regex-centric, fast lexical analyzer generator for C++ with full Unicode support. Faster than Flex. Accepts Flex specifications. Generates reusable source code that is easy to understand. Introduces indent/dedent anchors, lazy quantifiers, functions for lex/syntax error reporting, and more. Seamlessly integrates with Bison and other parsers.
Stars: ✭ 274 (-11.9%)
Mutual labels:  regex
Url Regex
Regular expression for matching URLs
Stars: ✭ 286 (-8.04%)
Mutual labels:  regex
core
🌈 light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection
Stars: ✭ 40 (-87.14%)
Mutual labels:  regex
Regex
Regular expressions for swift
Stars: ✭ 306 (-1.61%)
Mutual labels:  regex
Pyregex
pyregex is a Python Regular Expression Online Tester
Stars: ✭ 282 (-9.32%)
Mutual labels:  regex
Attributedstring
基于Swift插值方式优雅的构建富文本, 支持点击长按事件, 支持不同类型过滤, 支持自定义视图等.
Stars: ✭ 294 (-5.47%)
Mutual labels:  regex
pcre-net
PCRE.NET - Perl Compatible Regular Expressions for .NET
Stars: ✭ 114 (-63.34%)
Mutual labels:  regex
Kind Of
Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
Stars: ✭ 268 (-13.83%)
Mutual labels:  regex
Anymatch
‼️ Matches strings against configurable strings, globs, regular expressions, and/or functions
Stars: ✭ 289 (-7.07%)
Mutual labels:  regex
python-hslog
Python module to parse Hearthstone Power.log files
Stars: ✭ 37 (-88.1%)
Mutual labels:  regex
Hyperscan
High-performance regular expression matching library
Stars: ✭ 3,427 (+1001.93%)
Mutual labels:  regex
qunit-migrate
Migrate old QUnit tests to 2.x. Uses regex and ASTs to convert old QUnit code.
Stars: ✭ 17 (-94.53%)
Mutual labels:  regex
Rex
Your RegEx companion.
Stars: ✭ 283 (-9%)
Mutual labels:  regex
Regex
The Hoa\Regex library.
Stars: ✭ 308 (-0.96%)
Mutual labels:  regex
Bilibili Block List
基于正则表达式的Bilibili弹幕屏蔽规则
Stars: ✭ 304 (-2.25%)
Mutual labels:  regex
Idiosyncratic Ruby.com
Documenting All Ruby Specialities 💎︎
Stars: ✭ 292 (-6.11%)
Mutual labels:  regex

cursive_re

Readable regular expressions for Python 3.6 and up.

Installation

pip install cursive_re

Examples

>>> from cursive_re import *

>>> hash = text('#')
>>> hexdigit = any_of(in_range('0', '9') + in_range('a', 'f') + in_range('A', 'F'))
>>> hexcolor = (
...     beginning_of_line() + hash +
...     group(repeated(hexdigit, exactly=6) | repeated(hexdigit, exactly=3)) +
...     end_of_line()
... )
>>> str(hexcolor)
'^\\#([a-f0-9]{6}|[a-f0-9]{3})$'

>>> hexcolor_re = compile(hexcolor)
re.compile('^\\#([a-f0-9]{6}|[a-f0-9]{3})$')

>>> hexcolor_re.match('#fff')
<re.Match object; span=(0, 4), match='#fff'>

>>> hexcolor_re.match('#ffff') is None
True

>>> hexcolor_re.match('#ffffff')
<re.Match object; span=(0, 7), match='#ffffff'>

>>> domain_name = one_or_more(any_of(in_range('a', 'z') + in_range('0', '9') + text('-')))
>>> domain = domain_name + zero_or_more(text('.') + domain_name)
>>> path_segment = zero_or_more(none_of('/'))
>>> path = zero_or_more(text('/') + path_segment)
>>> url = (
...     group(one_or_more(any_of(in_range('a', 'z'))), name='scheme') + text('://') +
...     group(domain, name='domain') +
...     group(path, name='path')
... )
>>> str(url)
'(?P<scheme>[a-z]+)://(?P<domain>[a-z0-9\-]+(?:\.[a-z0-9\-]+)*)(?P<path>(?:/[^/]*)*)'

Reference

cursive_re.compile

Compile a cursive_re expression to a real regular expression.

cursive_re.beginning_of_line

Matches the beginning of a line.

Examples:

>>> str(beginning_of_line())
'^'

cursive_re.end_of_line

Matches the end of a line.

Examples:

>>> str(end_of_line())
'$'

cursive_re.anything

Matches any character.

Examples:

>>> str(anything())
'.'

cursive_re.literal

Inserts a literal regular expression.

Examples:

>>> str(literal(r"\A\w"))
'\\A\\w'

cursive_re.text

Matches the given string exactly, escaping any special characters.

Examples:

>>> str(text("abc"))
'abc'

cursive_re.any_of

Matches any of the given characters.

Examples:

>>> str(any_of("ab"))
'[ab]'

>>> str(any_of(text("ab")))
'[ab]'

>>> str(any_of(text("[]")))
'[\\[\\]]'

cursive_re.none_of

Matches none of the given characters.

Examples:

>>> str(none_of("ab"))
'[^ab]'

>>> str(none_of(text("ab")))
'[^ab]'

>>> str(none_of(text("[]")))
'[^\\[\\]]'

cursive_re.in_range

Matches a character in the given range.

Examples:

>>> str(in_range("a", "z"))
'a-z'

cursive_re.zero_or_more

Matches zero or more of the given expr.

Examples:

>>> str(zero_or_more("a"))
'(?:a)*'

>>> str(zero_or_more(text("a")))
'(?:a)*'

>>> str(zero_or_more(text("abc")))
'(?:abc)*'

>>> str(zero_or_more(group(text("abc"))))
'(abc)*'

cursive_re.one_or_more

Matches one or more of the given expr.

Examples:

>>> str(one_or_more("a"))
'(?:a)+'

>>> str(one_or_more(text("a")))
'(?:a)+'

>>> str(one_or_more(group(text("abc"))))
'(abc)+'

cursive_re.maybe

Matches an expr if present.

Examples:

>>> str(maybe("abc"))
'(?:abc)?'

>>> str(maybe(text("abc")))
'(?:abc)?'

>>> str(maybe(group(text("abc"))))
'(abc)?'

>>> str(maybe(any_of("abc")))
'[abc]?'

cursive_re.repeated

Matches an expr repeated an exact number of times.

Examples:

>>> str(repeated("a", exactly=5))
'(?:a){5}'

>>> str(repeated(text("a"), exactly=5))
'(?:a){5}'

>>> str(repeated(text("a"), at_least=1))
'(?:a){1,}'

>>> str(repeated(text("a"), at_most=5))
'(?:a){0,5}'

>>> str(repeated(text("a"), at_least=2, at_most=5, greedy=False))
'(?:a){2,5}?'

cursive_re.group

Denotes a group whose contents can be retrieved after a match is performed.

Examples:

>>> str(group(text("a")))
'(a)'

>>> str(group(any_of("abc"), name="chars"))
'(?P<chars>[abc])'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].