cfpq_data.grammars.readwrite.regex#

Read (and write) a regular expression from (and to) different sources.

Functions

regex_from_text(text)

Create a regular expression [1] from text.

regex_from_txt(path)

Create a regular expression [1] from TXT file.

regex_to_text(regex)

Turns a regular expression [1] into its text representation.

regex_to_txt(regex, path)

Saves a regular expression [1] text representation into TXT file.

regex_from_text(text: str) Regex[source]#

Create a regular expression [1] from text.

Parameters:

text (str) -- The text with which the regular expression will be created.

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> regex_to_text(regex)
'(a (bc|(d)*))'
Returns:

regex -- Regular expression.

Return type:

Regex

References

regex_from_txt(path: Path | str) Regex[source]#

Create a regular expression [1] from TXT file.

Parameters:

path (Union[Path, str]) -- The path to the TXT file with which the regular expression will be created.

Examples

>>> from cfpq_data import *
>>> regex_1 = regex_from_text("a (bc|d*)")
>>> path = regex_to_txt(regex_1, "test.txt")
>>> regex = regex_from_txt(path)
>>> regex_to_text(regex)
'(a (bc|(d)*))'
Returns:

regex -- Regular expression.

Return type:

Regex

References

regex_to_text(regex: Regex) str[source]#

Turns a regular expression [1] into its text representation.

Parameters:

regex (Regex) -- Regular expression.

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> regex_to_text(regex)
'(a (bc|(d)*))'
Returns:

text -- Regular expression text representation.

Return type:

str

References

regex_to_txt(regex: Regex, path: Path | str) Path[source]#

Saves a regular expression [1] text representation into TXT file.

Parameters:
  • regex (Regex) -- Regular expression.

  • path (Union[Path, str]) -- The path to the TXT file where regular expression text representation will be saved.

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> path = regex_to_txt(regex, "test.txt")
Returns:

path -- The path to the TXT file where regular expression text representation will be saved.

Return type:

Path

References