regexp

Python "re" shortcut library


Keywords
testing, logging, example
License
Other
Install
pip install regexp==0.1

Documentation

regexp

Python "re" shortcut library

Usage

Add to your Python script:

from regexp import *

Initialize the string you want to parse as r object:

my_string = 'The quick brown fox jumps over the lazy dog'
my_string = r(my_string)

string = r('Lorem ipsum dolor sit amet')

r(...).m(regex)

Get all substrings matched by the rule

>>> my_string.m('[bd]\S*')
['brown', 'dog']

r(...).mf(regex)

Get only the first substring matched by the rule

>>> my_string.mf('[bd]\S*')
['brown']

r(...).c(regex)

Check if the given regular expression works for the string

>>> my_string.c('\S+s')
True
>>> my_string.c('(alph|bet)a\s')
False

r(...).r(regex, replacement)

>>> r('Test string').r('t(?=r)', 'o')
Test soring

r(...).rf(regex, replacement)

>>> r('Test string').rf('(?<=s)t', 'o')
Teso string

r(...).d(regex)

>>> r('Test string').d('.\S*ing$')
Test

r(...).l(regex)

>>> r('Lorem ipsum dolor sit amet').l('[ida]\S+')
3

r(...).split(regex)

>>> r('Lorem ipsum dolor').split('\s*i\S+\s*')
['Lorem', 'dolor']