.. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead. .. _class_RegEx: RegEx ===== **Inherits:** :ref:`Reference` **<** :ref:`Object` **Category:** Core Brief Description ----------------- Simple regular expression matcher. Member Functions ---------------- +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`compile` **(** :ref:`String` pattern **)** | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_group_count` **(** **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_names` **(** **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_pattern` **(** **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_valid` **(** **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`RegExMatch` | :ref:`search` **(** :ref:`String` subject, :ref:`int` offset=0, :ref:`int` end=null **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`sub` **(** :ref:`String` subject, :ref:`String` replacement, :ref:`bool` all=false, :ref:`int` offset=null, :ref:`int` end=null **)** const | +--------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Description ----------- Class for finding text patterns in a string using regular expressions. It can not perform replacements. Regular expressions are a way to define patterns of text to be searched. Details on writing patterns are too long to explain here but the Internet is full of tutorials and detailed explanations. Once created, the RegEx object needs to be compiled with the pattern before it can be used. The pattern must be escaped first for gdscript before it is escaped for the expression. For example: ``var exp = RegEx.new()`` ``exp.compile("\\d+")`` would be read by RegEx as ``\d+`` Similarly: ``exp.compile("\"(?:\\\\.|[^\"])\*\"")`` would be read as ``"(?:\\.|[^"])\*"`` Currently supported features: \* Capturing ``()`` and non-capturing ``(?:)`` groups \* Named capturing groups ``(?P)`` \* Any character ``.`` \* Shorthand character classes ``\w \W \s \S \d \D`` \* User-defined character classes such as ``[A-Za-z]`` \* Simple quantifiers ``?``, ``\*`` and ``+`` \* Range quantifiers ``{x,y}`` \* Lazy (non-greedy) quantifiers ``\*?`` \* Beginning ``^`` and end ``$`` anchors \* Alternation ``|`` \* Backreferences ``\1``, ``\g{1}``, and ``\g`` \* POSIX character classes ``[[:alnum:]]`` \* Lookahead ``(?=)``, ``(?!)`` and lookbehind ``(?<=)``, ``(?` **compile** **(** :ref:`String` pattern **)** Compiles and assign the regular expression pattern to use. .. _class_RegEx_get_group_count: - :ref:`int` **get_group_count** **(** **)** const Returns the number of numeric capturing groups. .. _class_RegEx_get_names: - :ref:`Array` **get_names** **(** **)** const Returns an array of names of named capturing groups. .. _class_RegEx_get_pattern: - :ref:`String` **get_pattern** **(** **)** const Returns the expression used to compile the code. .. _class_RegEx_is_valid: - :ref:`bool` **is_valid** **(** **)** const Returns whether this object has a valid regular expression assigned. .. _class_RegEx_search: - :ref:`RegExMatch` **search** **(** :ref:`String` subject, :ref:`int` offset=0, :ref:`int` end=null **)** const Searches the text for the compiled pattern. Returns a :ref:`RegExMatch` container of the first matching reult if found, otherwise null. The region to search within can be specified without modifying where the start and end anchor would be. .. _class_RegEx_sub: - :ref:`String` **sub** **(** :ref:`String` subject, :ref:`String` replacement, :ref:`bool` all=false, :ref:`int` offset=null, :ref:`int` end=null **)** const Searches the text for the compiled pattern and replaces it with the specified string. Escapes and backreferences such as ``\1`` and ``\g`` expanded and resolved. By default only the first instance is replaced but it can be changed for all instances (global replacement). The region to search within can be specified without modifying where the start and end anchor would be.