LassoScript Utility
Basics Browse Detail


Tag Link [RegExp] Category String
Type Substitution Source Available Yes
Support Preferred Version 8.5
Change New Data Source Any
Output Type RegExp Security None
Implementation Sets Lasso 8.5


[RegExp] is a data type which represents a compiled regular expression that can be used again and again. The type makes it possible to perform interactive search/replace operations on strings where each replacement string is determined programmatically and to split strings using a regular expression.

Note - The [String_ReplaceRegExp] and [String_FindRegExp] tags also provide regular extension functionality may be preferable for simple search/replace or extract operations.

The regular expression data type stores a find pattern, a replacement pattern, an input string, and an output string. By default regular expressions are case sensitive, but a regular expression object can also be set to ignore case.

The parameters of the [RegExp] tag accepts parameters corresponding to the stored patterns and strings for the data type. The -Find parameter is required and specifies the initial regular expression which will be compiled and stored as the find pattern. An optional -Replace parameters specifies a replace pattern. An optional -Input parameter specifies an input string. And, an optional -IgnoreCase parameter sets the regular expression to ignore case when performing matches.

The member tags of the regular expression type allow the [RegExp->FindPattern], [RegExp->ReplacePattern], [RegExp->Input], [RegExp->Output], and [RegExp->IgnoreCase] values to be inspected or modified. The [RegExp->GroupCount] tag returns the number of groups found in the find pattern.

The [RegExp->ReplaceAll] and [RegExp->ReplaceFirst] tags perform a search/replace operation on the input string using the find and replace patterns. The [RegExp->Split] tags performs a split operation on the input string using the find and replace patterns. Either the string and patterns stored in the regular expression can be used or new values can be specified when calling the tags.

The [RegExp->Matches] and [RegExp->MatchesStart] tags return true if the find pattern matches the input string exactly or matches the start of the input string.

The remainder of the member tags are used for interactive search/replace operations. [RegExp->Find] starts an interactive search/replace by finding the first instance of the find pattern in the input string. Subsequent calls to [RegExp->Find] advance the find pattern through the input string. The tag returns true if the find pattern could be advanced or false otherwise. Each time [RegExp->Find] is called any part of the input string that is skipped over is automaticaly appended to the output.

After calling [RegExp->Find] the [RegExp->MatchString] tag returns the current match and the [RegExp->MatchPosition] tag returns the location of the current match. The [RegExp->AppendReplacement] tag can be used to insert a replacement string into the output. At the end of the interactive search/replace operation [RegExp->AppendTail] appends the remainder of the input string onto the output string.

The [RegExp->Reset] tag resets the state of the [RegExp->Find] tag and moves the current output string into the input string. This allows an interactive search/replace operation to be performed, reset, and then performed again on the result of the prior operation.

The current output string can be returned with [RegExp->Output] or is returned when the regular expression data type is cast to string. If the regular expression is cast to string and no output has been generated then [RegExp->ReplaceAll] is called to generate an output string.


[Var: 'myRegExp' = (RegExp: -Find='(\\w)(\\w+)')]
[$myRegexp->(Input: 'the lazy dog')]
[While: $myRegExp->Find]
[Var: 'myReplacement' = (String_Uppercase: $MyRegExp->(MatchString: 1))]
[$myRegExp->(AppendReplacement: $myReplacement)]
[$myRegExp->(AppendReplacement: $MyRegExp->(MatchString: 2))]


Required Parameters
-Find Specifies the find pattern to use for subsequent search/replace operations.
Optional Parameters
-Replace Specifies a replacement pattern to use for subsequent search/replace operations. Defaults to empty.
-Input Specifies the input to use for the next the search/replace operation. Defaults to empty.
-IgnoreCase If specified subsequent search/replace operations will be performed without regard to case. Defaults to performing case sensitive search/replace operations.


See the Lasso 8 Language Guide for examples of how to use this tag.

Related Tags

Category Tags