Lasso Soft Inc. > Home

[ String_FindRegExp ]

Method

[String_FindRegExp] takes two parameters: a string value and a -Find keyword/value parameter. Returns an array with each instance of the -Find regular expression in the string parameter.

If groups are defined in the -Find expression then the output contains the entire search result followed by each of the sub-groups. If there were 2 matches of the expressions and 2 sub-groups then the array contains a total of 6 items.

The following matching symbols are available in regular expressions. Each of these symbols matches a single character. Multiple characters are matched by combining these symbols with the combination symbols in the next table.

Note - Regular expressions in Lasso require double backslashes as shown in the listing below.

a-z A-Z 0-9 - Alphanumeric characters match the specified character.
. - Period matches any single character.
^ - Circumflex matches the beginning of a line.
$ - Dollar sign matches the end of a line.
\\... - A backslash escapes the next character. \\\\ represents a backslash.
[...] - Square brackets create a character class matching any character included inside.
[^...] - With a carat, any character other than those included inside is matched.
[a-z] - A range of characters can be specified.
\t - A tab character.
\r - A return character.
\n - A new-line character.
\" - A double quote.
\' - A single quote.
\\w - Matches any alphanumeric character or an underscore.
\\W - Matches any non-alphanumeric character.
\\s - Matches a whitespace character (space, tab, return, etc.).
\\S - Matches a non-whitespace character.
\\d - Matches a numeric digit.
\\D - Matches any non-numeric character.

The following combination symbols are used to combine matching symbols into complex expressions. For example a+ would match one or more a characters.

| - Alternation. Matches either the character before or the character after the symbol.
( ) - Grouping. Defines a named group for output. Nine pairs of parentheses can be defined.
* - Asterisk matches 0 or more repetitions of the preceding character.
+ - Plus sign matches 1 or more repetitions of the preceding character.
? - Question mark matches 0 or 1 repetitions of the preceding character.
{n} - Matches n repetitions of the preceding character.
{n,} - Matches at least n repetitions of the preceding character.
{n,m} - Matches at least n, but no more than m repetitions of the preceding character.

  • Syntax
String_FindRegExp(
    'String Value',
    -Find='Regular Expression'
)

String_FindRegExp(
    'String Value',
    -Find='Regular Expression',
    -IgnoreCase
)
Examples
  • Beginner

To find all email addresses within a string:

Use the [String_FindRegExp] method. The following example returns an array of all email addresses in a string. The email addresses are returned complete, then separated into username and domain name.

Code

string_findregexp('Send email to lassodocumentation@lassosoft.com',   -find='(\\w+)@(\\w+\\.\\w+)')

Result

array(lassodocumentation@lassosoft.com, lassodocumentation, lassosoft.com)
Resources
  • Tips

Use the Regular Expression Utility to write Lasso code with proper escaping automatically.

http://reference.lassosoft.com/Reference.LassoApp?utility/regexp

The following websites are resources for regular expressions.

http://www.regular-expressions.info/

http://regexlib.com/DisplayPatterns.aspx

Recent Comments

No Comments found

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