We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some prototype code:
import re def convert_posix_to_python(posix_regex): """ Convert common POSIX regular expressions to Python regular expressions. """ # Dictionary of POSIX to Python character class conversions posix_to_python_classes = { r'\[\[:alnum:\]\]': r'[a-zA-Z0-9]', r'\[\[:alpha:\]\]': r'[a-zA-Z]', r'\[\[:digit:\]\]': r'\d', r'\[\[:xdigit:\]\]': r'[0-9a-fA-F]', r'\[\[:lower:\]\]': r'[a-z]', r'\[\[:upper:\]\]': r'[A-Z]', r'\[\[:blank:\]\]': r'[ \t]', r'\[\[:space:\]\]': r'\s', r'\[\[:punct:\]\]': r'[!"#$%&\'()*+,\-./:;<=>?@[\\\]^_`{|}~]', r'\[\[:word:\]\]': r'\w' } # Replace POSIX character classes with Python equivalents for posix_class, python_class in posix_to_python_classes.items(): posix_regex = re.sub(posix_class, python_class, posix_regex) # Replace POSIX quantifiers with Python equivalents posix_regex = posix_regex.replace(r'\{', '{').replace(r'\}', '}') return posix_regex # Example usage posix_regex = r'r[[:digit:]]\{1,\}i[[:digit:]]\{1,\}p[[:digit:]]\{1,\}f[[:digit:]]\{1,\}$' python_regex = convert_posix_to_python(posix_regex) print("Converted Python regex:", python_regex)
The text was updated successfully, but these errors were encountered:
That looks nice, we can add this in the next PR.
Sorry, something went wrong.
No branches or pull requests
some prototype code:
The text was updated successfully, but these errors were encountered: