public class RegEx extends Object:
Regular expressions are natively supported by the language, following Perl-like syntax. The RegEx class provides methods for matching, searching, replacing, and splitting strings based on regular expression patterns.
Here are some examples of how to use the RegEx class:
regex = RegEx("^\\d+$")You can also define regex patterns using raw string literals to avoid escaping backslashes.
regex = RegEx(r"^\d+$")
Notice also that Klyn language support a native syntax like Perl or JavaScript for regex literals, which can be used directly without the need for escaping backslashes.
regex = /^\d+$/
| Modifier and Type | Member | Description |
|---|---|---|
| public property | flagsflags as Int |
No summary. |
| public property | patternpattern as String |
No summary. |
| Modifier and Type | Member | Description |
|---|---|---|
| public native | RegEx | RegEx constructor. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | findfind(input as String) as MatchResult: |
Finds the first occurrence of the pattern in the input. |
| public | findAllfindAll(input as String) as Array<MatchResult>: |
Finds all occurrences of the pattern in the input. |
| public native | matchermatcher(input as String) as RegExMatcher: |
Creates a matcher for the regular expression. |
| public native | matches | Checks if the input matches the pattern. |
| public native | replace | Replaces all occurrences of the pattern with a replacement string. |
| public native | replaceFirst | Replaces the first occurrence of the pattern with a replacement string. |
| public native | replaceLast | Replaces the last occurrence of the pattern with a replacement string. |
| public native | split | Splits the input into an array of substrings using the pattern as a delimiter. |