Lasso Soft Inc. > Home

[ regexp ]

Type

No description available.

  • Syntax
  • Methods
  • Traits
No syntax description available at this time.
Has methods:
Has traits:
Examples
  • Beginner
  • Intermediate

Remove anything but digits from a string containing a phone number.

It's a good habit to use back-ticks instead of quotes to enclose find and replace patterns in a [regexp] object since it won't need special handling of escape characters.

Code

regexp(-find = `\D+`, -input = 'Phone: 905 251-6169', -ignorecase) -> replaceall

Result

-> 9052516169

Task at hand, find the name that's in-between the <h1></h1> tags of a given html snippet. There can be both line feeds and tabs that we don't want as part of the result.

To extract the name value we do a two step operation. First replace any kind of line feeds or tabs with nothing. Next step is to weed out the content between the <h1></h1> tag.

The [regexp] methods we use is [replaceall], [input], [findpattern], [find] and [matchstring]. To remove possible extra space before and after the resulting string we trim it.

Code

var(myhtml = '<!DOCTYPE html>
<html lang="en">
<head>
	<title>Testing regexp</title>
</head>
<body>
	<h1>
		LassoSoft Inc - The Rhino from Canada 
	</h1>
</body>
</html>')

var(reg_exp = regexp(-find = `(\r\n)+|\r+|\n+|\t+`, -replace = ``, -input = $myhtml))

var(strippedhtml = $reg_exp -> replaceall)

$reg_exp -> input = $strippedhtml

$reg_exp -> findpattern = `<h1>(.*?)</h1>`
var(final = ($reg_exp -> find ? $reg_exp -> matchstring(1) | 'Not found') -> trim &)

$final

Result

-> LassoSoft Inc - The Rhino from Canada

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