Lasso Soft Inc. > Home

[RegExp->Find]

[RegExp->Find] is used in interactive search/replace operations. The first time this tag is called it finds the first instance of the find pattern in the input string and returns true if successful. An optional parameter specifies the position in the input string at which to start the find operation. Subsequent calls to the tag advance through the input string until the find pattern cannot be found any more. The tag returns true each time it can successfully advance and false otherwise.

The tag is usually used as the condition of a [While] ... [/While] loop. The first call initializes the first match and the tag is then called repeatedly until it returns false signaling the last match.

When [RegExp->Find] is called it activates the [RegExp->MatchPosition] and [RegExp->MatchString] tags with information about the current match. The first tag returns the position in the input string of the match and the second tag returns the matched substring. Either tag accepts an optional integer parameter to return information about one of the groups from the find pattern rather than the entire pattern.

The [RegExp->Find] tag automatically appends the portion of the input string which it advances over into the output string. In an interactive search/replace operation the [RegExp->MatchString] is used to generate a new replacement value. This value is appended onto the output using [RegExp->AppendReplacement]. By alternately calling [RegExp->Find] and [RegExp->AppendReplacement] the entire input string is processed and a new output string is assembled.

After [RegExp->Find] returns false the [RegExp->AppendTail] tag should be called to append the remainder of the input string onto the output string. Finally, [RegExp->Output] can be used to return the output string (or the regular expression object can be cast to string).

[RegExp->Reset] resets the state of the [RegExp->Find] object and also sets the input string to the current output string. After performing an interactive search/replace operation [RegExp->Reset] can be called to start another search/replace operation on the output of the prior operation.

  • Syntax
  • Parameters
[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))]
[/While]
[$myRegExp->AppendTail]
[$myRegExp->Output]
Optional Parameters
Position The position at which to start searching the input string. By default the position starts at 1 and increments to the end of the match found by the previous find operation.
Examples

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

Tag Link [RegExp->Find] Category String
Type Member Data Source Any
Support Preferred Version 8.5
Output Type Boolean Security None
Implementation Sets Lasso 8.5

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft