Io Reference







Parsers   /   Regex   /   Regex





The Regex addon adds support for Perl regular expressions using the PCRE library by Philip Hazel.

Example 1

	
Io> re := "is.*a" asRegex
Io> "This is a test. This is also a test." \
    allMatchesOfRegex(" is[^.]*a") replaceAllWith(" is not a")
==> "This is not a test. This is not a test.

Example 2

	
Io> "11aabb" allMatchesOfRegex("aa*")
==> list("a", "a")

Io> re := "(wom)(bat)" asRegex
Io> "wombats are cuddly" matchesOfRegex(re) replaceAllWith("$2$1!")
==> batwom!s are cuddly
 
 
 



asRegex

Returns self.
asString

Returns a string containing a textual representation of the receiver.
captureCount

Returns the number of captures defined by the pattern.
caseless

Returns a case insensitive clone of the receiver, or self if the receiver itself is case insensitive:
	
	Io> "WORD" matchesRegex("[a-z]+")
	==> false

	Io> "WORD" matchesRegex("[a-z]+" asRegex caseless)
	==> true
	
dotAll

Returns a clone of the receiver with the dotall option turned on, or self if the receiver itself has the option turned on.

In dotall mode, "." matches any character, including newline. By default it matches any character except newline.

	
	Io> "A\nB" matchesOfRegex(".+") next string
	==> A

	Io> "A\nB" matchesOfRegex(".+" asRegex dotAll) next string
	==> A\nB
	
extended

Returns a clone of the receiver with the extended option turned on, or self if the receiver itself has the option turned on.

In extended mode, a Regex ignores any whitespace character in the pattern except when escaped or inside a character class. This allows you to write clearer patterns that may be broken up into several lines.

Additionally, you can put comments in the pattern. A comment starts with a "#" character and continues to the end of the line, unless the "#" is escaped or is inside a character class.

isCaseless

Returns true if the receiver is case insensitive, false if not.
isDotAll

Returns true if the receiver is in dotall mode, false if not.
isExtended

Returns true if the receiver is in extended mode, false if not.
isMultiline

Returns true if the receiver is in multiline mode, false if not.
matchesIn(aString)

Returns a RegexMatches object that enumerates the matches of the receiver in the given string.
multiline

Returns a clone of the receiver with the multiline option turned on, or self if the receiver itself has the option turned on.

In multiline mode, "^" matches at the beginning of the string and at the beginning of each line; and "$" matches at the end of the string, and at the end of each line. By default "^" only matches at the beginning of the string, and "$" only matches at the end of the string.

	
	Io> "A\nB\nC" allMatchesForRegex("^.")
	==> list("A")

	Io> "A\nB\nC" allMatchesForRegex("^." asRegex multiline)
	==> list("A", "B", "C")
	
nameTable

Returns a list with the name of each capture. The first element will always be nil, because it corresponds to the whole match. The second element will contain the name of the first capture, or nil if the first capture has no name. And so on.
namedCaptures

Returns a Map that contains the index of each named group.
names

Returns a list of the name of each named capture. If there are no named captures, the list will be empty.
notCaseless

The reverse of caseless.
notDotAll

The reverse of dotAll.
notExtended

The reverse of extended.
notMultiline

The reverse of multiline.
pattern

Returns the pattern string that the receiver was created from.
version

Returns a string with PCRE version information.
with(pattern)

Returns a new Regex created from the given pattern string.