class_regex.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. .. _class_RegEx:
  2. RegEx
  3. =====
  4. **Inherits:** :ref:`Reference<class_reference>`
  5. **Category:** Core
  6. Simple regular expression matcher.
  7. Member Functions
  8. ----------------
  9. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  10. | :ref:`int<class_int>` | :ref:`compile<class_RegEx_compile>` **(** :ref:`String<class_string>` pattern, :ref:`int<class_int>` capture=9 **)** |
  11. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  12. | :ref:`int<class_int>` | :ref:`find<class_RegEx_find>` **(** :ref:`String<class_string>` text, :ref:`int<class_int>` start=0, :ref:`int<class_int>` end=-1 **)** const |
  13. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`clear<class_RegEx_clear>` **(** **)** |
  15. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`bool<class_bool>` | :ref:`is_valid<class_RegEx_is_valid>` **(** **)** const |
  17. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`int<class_int>` | :ref:`get_capture_count<class_RegEx_get_capture_count>` **(** **)** const |
  19. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_string>` | :ref:`get_capture<class_RegEx_get_capture>` **(** :ref:`int<class_int>` capture **)** const |
  21. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`StringArray<class_stringarray>` | :ref:`get_captures<class_RegEx_get_captures>` **(** **)** const |
  23. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  24. Description
  25. -----------
  26. Class for finding text patterns in a string using regular expressions. Regular expressions are a way to define patterns of text to be searched.
  27. This class only finds patterns in a string. It can not perform replacements.
  28. Usage of regular expressions is too long to be explained here, but Internet is full of tutorials and detailed explanations.
  29. Currently supported features:
  30. Capturing ``()`` and non-capturing ``(?:)`` groups
  31. Any character ``.``
  32. Shorthand caracter classes ``\w \W \s \S \d \D``
  33. User-defined character classes such as ``:ref:`A-Za-z<class_a-za-z>```
  34. Simple quantifiers ``?``, ``\*`` and ``+``
  35. Range quantifiers ``{x,y}``
  36. Lazy (non-greedy) quantifiers ``\*?``
  37. Begining ``^`` and end ``$`` anchors
  38. Alternation ``|``
  39. Backreferences ``\1`` and ``\g{1}``
  40. POSIX character classes ``:ref:`[:alnum:<class_[:alnum:>`]``
  41. Lookahead ``(?=)``, ``(?!)`` and lookbehind ``(?<=)``, ``(?<!)``
  42. ASCII ``\xFF`` and Unicode ``\uFFFF`` code points (in a style similar to Python)
  43. Word boundaries ``\b``, ``\B``
  44. Member Function Description
  45. ---------------------------
  46. .. _class_RegEx_compile:
  47. - :ref:`int<class_int>` **compile** **(** :ref:`String<class_string>` pattern, :ref:`int<class_int>` capture=9 **)**
  48. Compiles and assign the regular expression pattern to use. The limit on the number of capturing groups can be specified or made unlimited if negative.
  49. .. _class_RegEx_find:
  50. - :ref:`int<class_int>` **find** **(** :ref:`String<class_string>` text, :ref:`int<class_int>` start=0, :ref:`int<class_int>` end=-1 **)** const
  51. This method tries to find the pattern within the string, and returns the position where it was found. It also stores any capturing group (see :ref:`get_capture<RegEx_get_capture>`) for further retrieval.
  52. .. _class_RegEx_clear:
  53. - void **clear** **(** **)**
  54. This method resets the state of the object, as it was freshly created. Namely, it unassigns the regular expression of this object, and forgets all captures made by the last :ref:`find<RegEx_find>`.
  55. .. _class_RegEx_is_valid:
  56. - :ref:`bool<class_bool>` **is_valid** **(** **)** const
  57. Returns whether this object has a valid regular expression assigned.
  58. .. _class_RegEx_get_capture_count:
  59. - :ref:`int<class_int>` **get_capture_count** **(** **)** const
  60. Returns the number of capturing groups. A captured group is the part of a string that matches a part of the pattern delimited by parentheses (unless they are non-capturing parentheses *(?:)*).
  61. .. _class_RegEx_get_capture:
  62. - :ref:`String<class_string>` **get_capture** **(** :ref:`int<class_int>` capture **)** const
  63. Returns a captured group. A captured group is the part of a string that matches a part of the pattern delimited by parentheses (unless they are non-capturing parentheses *(?:)*).
  64. .. _class_RegEx_get_captures:
  65. - :ref:`StringArray<class_stringarray>` **get_captures** **(** **)** const
  66. Return a list of all the captures made by the regular expression.