The regular expression.
Julian implements a core regex in a similar syntax as Perl and JavaScript, but intentionally doesn't build extension features into it, such as various named patterns, occurrence count, non-greedy matching, etc. If advanced feature is required, the user can use type mapping API to call directly to regex facilities provided by the platform.
The supported constructs include:
a|b
abc
? * +
(representing zero-or-one, zero-or-more and one-or-more, respectively)[a-zA-Z]
[^0-9]
.
matches every character^
matches the start of input$
matches the end of input()
to capture the groups. Groups can be retrieved by Match.getGroup(int). Regex r = new Regex("(a?(b*)c?)"); // There will be two groups in the matching result, if matched.
Regex r = /ab*d?e/;
. | - ( ) [ ] ? * + \
. If matching a character which happens to be the metacharacter, use \
to escape: Regex r = /a\.b/; // Matches exactly "a.b", not "a{any character}b"
Match m = /ab+c/.matchAll("abbbbc");
bool result = m.isMatched(); // true
m.next(); // since we have matched the entire string, this will only result in a mismatch
result = m.isMatched(); // false
Match m = /ab+c/.matchNext("abbbbcacabc");
while (m.isMatched()) {
string text = m.getText(); // Get the matched text;
Console.println(text);
m.next(); // Match the next occurrence pattern "ab+c"
}
// (output)
// abbbbc
// abc
Parent Class
Type | Name | Signature |
---|---|---|
constructor | Regex | public Regex(string) |
method | matchAll | public Match matchAll(string) |
method | matchNext | public Match matchNext(string) |
public Regex(string pattern)
Create a new Regex object with the given pattern.
Parameters
Throws
public Match matchAll(string input)
Match the entire input against this pattern.
Parameters
Returns
public Match matchNext(string input)
Find the first occurrence of the pattern in the given input.
Parameters
Returns