Skip to content
QiTASC.com / intaQt Built-ins /
Regex Built-ins
/ .. /
Regex Built-ins





Regex Built-ins

Regex Built-ins create Regexes, as well as match and extract Regex objects.

Define Regex

This function creates a regex that matching functions can be applied to.

Syntax

1
<newRegex Regex> := regex(<regex String>)

Returns
The new regex object.

Parameter

  • regex - The regex

Example

1
re1 := regex("hello.*")

Match Entire String

This function checks if an entire string matches the specified criteria.

Syntax

1
<result Boolean> := <regex Regex>.matches(<text String>)

Returns
true if the entire string matches the specified text. false otherwise.

Parameters

  • regex - The regex defined by the regex() function

  • text - The text to match against the regex object

Example

1
2
re1 := regex("hello.*")
assert re1.matches("hello world")

Match Partial String

This function defines a regex then searches a string for a partial match.

Syntax

1
<result Boolean> := <regex Regex>.containsMatchIn(<text String>)

Returns
true if a partial match is found, false otherwise.

Parameters

  • regex - The regex created by the regex() function

  • text - The text to partially match against the regex object

Example

1
2
re2 := regex("ello")
assert re2.containsMatchIn("hello world")

The example above will return true because "ello" is a partial match of "hello world".

Find First Match

This function uses a regex to extract part of a string.

Syntax

1
<foundFirstMatch String> := <regex Object>.findFirstMatch(<text String>)

Returns
The first match found in a string. If no match is found, null is returned.

Parameters

  • regex - The regex defined by the regex() function

  • text - The text to be extracted against the regex object

Example 1- Match Single Digiti

1
2
text := "Some digits 1 2 3 4 5 ... 8 9 10 11"
re1 := regex(".*(\\d).*")

Example 2 - Returns 1

1
2
text := "Some digits 1 2 3 4 5 ... 8 9 10 11"
firstRegexMatch := re1.findFirstMatch(text)

Example 3 - Match at Least 2 Digits

1
2
text := "Some digits 1 2 3 4 5 ... 8 9 10 11"
re2 := regex(".*?(\\d{2,}).*")

Example 4 - Returns 10

1
2
text := "Some digits 1 2 3 4 5 ... 8 9 10 11"
firstRegexMatch := re2.findFirstMatch(text)