
정규 표현식을 위한 비정규적인 방법들.
Exrex는 주어진 정규 표현식과 일치하는 모든(또는 무작위) 문자열을 생성하는 명령줄 도구이자 Python 모듈입니다. 순수 Python으로 작성되었으며, 외부 의존성이 없습니다.
일치하는 문자열이 무한한 정규 표현식(예: [a-z]+)도 있으며, 이런 경우 exrex는 무한 부분의 최대 길이를 제한합니다.
Exrex는 제너레이터를 사용하므로, 메모리 사용량은 일치하는 문자열의 수에 의존하지 않습니다.
기능
exrex를 설치하려면, 다음을 실행하세요:
$ pip install exrex
또는
$ easy_install exrex
>>> import exrex
>>> exrex.getone('(ex)r\\1')
'exrex'
>>> list(exrex.generate('((hai){2}|world!)'))
['haihai', 'world!']
>>> exrex.getone('\d{4}-\d{4}-\d{4}-[0-9]{4}')
'3096-7886-2834-5671'
>>> exrex.getone('(1[0-2]|0[1-9])(:[0-5]\d){2} (A|P)M')
'09:31:40 AM'
>>> exrex.count('[01]{0,9}')
1023
>>> print '\n'.join(exrex.generate('This is (a (code|cake|test)|an (apple|elf|output))\.'))
This is a code.
This is a cake.
This is a test.
This is an apple.
This is an elf.
This is an output.
>>> print exrex.simplify('(ab|ac|ad)')
(a[bcd])
> exrex --help
usage: exrex.py [-h] [-o FILE] [-l] [-d DELIMITER] [-v] REGEX
exrex - regular expression string generator
positional arguments:
REGEX REGEX string
optional arguments:
-h, --help show this help message and exit
-o FILE, --output FILE
Output file - default is STDOUT
-l N, --limit N Max limit for range size - default is 20
-c, --count Count matching strings
-m N, --max-number N Max number of strings - default is -1
-r, --random Returns a random string that matches to the regex
-s, --simplify Simplifies a regular expression
-d DELIMITER, --delimiter DELIMITER
Delimiter - default is \n
-v, --verbose Verbose mode
예시:
$ exrex '[asdfg]'
a
s
d
f
g
$ exrex -r '(0[1-9]|1[012])-\d{2}'
09-85
$ exrex '[01]{10}' -c
1024
버그 또는 제안? 이슈 트래커를 방문하세요.
http://exrex.readthedocs.org/en/latest/
re.sre_parse.CATEGORIES) (30%)n개 생성exrex is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
exrex is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with exrex. If not, see < http://www.gnu.org/licenses/ >.
(C) 2012- by Adam Tauber, <[email protected]>
exrex '( {20}(\| *\\|-{22}|\|)|\.={50}| ( ){0,5}\\\.| {12}~{39})'exrex '(o|O|0)(_)(o|O|0)'주어진 패턴과 일치하는 모든 가능한 문자열 목록을 생성하는 도구:
주어진 패턴과 일치하는 무작위 문자열을 하나씩 생성하는 도구:
rstr Python 모듈의 메서드)python -m cProfile exrex.py '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' -o /dev/nullpython -m cProfile exrex.py '[0-9]{6}' -o /dev/null