Source Code

This module provides basic cross-platform regular expression support. It's based on Google's RegExp object for GWT.

For documentation pertaining to regular expressions and patterns take a look at the information for the original implementations:

A simple example of how to use this module:

Regex re = regex("[0-9]+ years");
assert(re.test("90 years old"));
print(re.replace("90 years old", "very"));

For more information see regex() and Regex.

By: Tako Schotanus
License: Apache Software License 2.0
java.base (jvm)7
quoteSource Codeshared String quote(String input)

This method produces a String that can be used to create a Regex that would match the string as if it were a literal pattern. Metacharacters or escape sequences in the input sequence will be given no special meaning.

  • input

    The string to be literalized

regexSource Codeshared Regex regex(String expression, Boolean global = false, Boolean ignoreCase = false, Boolean multiLine = false)

Factory method that returns an initialized Regex object for the current backend. See the documentation for the Regex object itself for more information.

  • expression

    The regular expression to be used for all operations

  • global = false

    For returning all matches instead of only the first

  • ignoreCase = false

    For case-insensitive matching

  • multiLine = false

    For multi-line matching where ^ and $ also match line delimiters and not just the beginning or end of the entire input string

MatchResultSource Codeshared MatchResult

The result of a call to Regex.find()

RegexSource Codeshared abstract sealed Regex

A class for cross-platform regular expressions modeled on Javascript's RegExp, plus some extra methods like Java's and Javascript String's replace and split methods (taking a RegExp parameter) that are missing from Ceylon's version of String. To create an instance of this class use the toplevel function regex().

Example usage:

Regex re = regex("[0-9]+ years");
assert(re.test("90 years old"));
print(re.replace("90 years old", "very"));

There are a few small incompatibilities between the two implementations. Java-specific constructs in the regular expression syntax (e.g. [a-z&&[^bc]], (?<=foo), \A, \Q) work only on the JVM backend, while the Javascript-specific constructs $` and $' in the replacement expression work only on the Javascript backend, not the JVM backend, which rejects them. There are also sure to exist small differences between the different browser implementations, be sure to test thoroughly, especially when using more advanced features.

RegexExceptionSource Codeshared RegexException

An exception that can be thrown when the Regex object couldn't be created or when an error occurred in any of its methods