Language Reference
Documentation

Language

Objects
Internet Objects

RegEx Class

Has Constructor: NO, Can Create Instance: YES
Can Subclass: YES

User the RegEx object to perform search and replacements on strings using Regular Expressions. To create a new RegEx object declare a variable of type color and then create a new instance with the NEW statement.

See Also: RegExMatch

Methods

replace
Syntax: regex.replace(target string, [startpos] as integer) as string

Finds SearchPattern in the target string and replaces the contents of SearchPattern with ReplacementPattern. Returns the resulting string.

search
Syntax: regex.search(target string, [startpos] as integer) as RegExMatch

Finds SearchPattern in the target string. Returns a RegExMatch object.

Properties

SearchPattern
Data Type: String

A string with the regular expression.

ReplacementPattern
Data Type: String

A string with a replacement expression. The '\1' or '$1' notation is supported.

Greedy
Data Type: Integer

If true (1) the regex engine will perform a greedy search.

DotMatchAll
Data Type: Integer

If true (1) the dot will match new lines. The default value is false (0).

CaseSensitive
Data Type: Integer

If true the serch will be case sensitive. The default value is false (0).

Sample Code

sub main()
dim s as string, m as string
dim r as regEx,rm as regExMatch

msgbox("RegEx Class Test")
//setup the source string

s = "<html><head><title>Hello</title></head><body><b>My bold 1</b>"
s = s & "<br><b>My bold 2</b><u>some underline</u>"
s = s & "<b>Hello bold 3</b></body></html>"

r = new regEx

//find bold tags
r.searchpattern = "<b>.+?</b>"
r.greedy = false

rm = r.search(s)

dim i as integer,c as integer

if rm.nil = true then
    msgbox("Text not found")
    quit
end if

while rm.nil = false
    m = rm.SubExpressionString(0)
    msgbox("Matched:\n" & m)
    i = strlib.len(m) + rm.subExpressionStart(0)
    rm = r.search(s,i)
wend

end sub