项目作者: alvarofpp

项目描述 :
Maker Regular Expressions
高级语言: Python
项目地址: git://github.com/alvarofpp/mre.git
创建时间: 2018-11-05T14:21:50Z
项目社区:https://github.com/alvarofpp/mre

开源协议:MIT License

下载


Maker Regular Expression


PyPI

This is a simple package to make regular expressions in Python.

  1. pip install mre

Documentation

Examples

  1. from mre import Regex, Group
  2. rgx_one = Regex("Hello world") # Hello world
  3. rgx_two = Regex("Hello", " world") # Hello world
  4. rgx_three = Regex("Hello") + " " + Regex("world") # Hello world
  5. rgx_four = Regex('<', Group('h[1-6]'), '>') # <(h[1-6])>
  6. rgx_five = Regex('<', Regex.SLASH, 1, '>') # <\/\1>
  1. from mre import Set
  2. from mre.helper import Range
  3. # All digits
  4. digits = Set(Range(0, 9))
  5. # Add comment
  6. digits = digits.comment('Get all digits')
  7. # Output: [0-9](?#Get all digits)
  1. from mre import Regex, Set, Comment
  2. # All digits
  3. digits = Set(Regex("0-9"))
  4. # CEP comment
  5. cep_comment = Comment('Get zip code Brazil on input')
  6. # CEP regex
  7. rgx_cep = Regex(
  8. digits.quantifier(5),
  9. Regex("-").quantifier(0, 1),
  10. digits.quantifier(3),
  11. cep_comment
  12. )
  13. # Output: [0-9]{5}-?[0-9]{3}(?#Get zip code Brazil on input)

Tests

To test the package just run the following command:

  1. # (first time only) Build the Docker image
  2. make build
  3. # Run tests
  4. make test
  5. # Run tests and check coverage
  6. make test-coverage

Contributing

Contributions are more than welcome. Fork, improve and make a pull request.
For bugs, ideas for improvement or other, please create an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.