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:

By: Tako Schotanus
License: Apache Software License 2.0
Dependencies (jvm)1.2.1
java.base (jvm)8
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 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.

Example usage:

value 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