Lasso Soft Inc. > Home

  • Articles

Handy regexp to find all form field names in HTML with Lasso 9

By Jolle Carlestam

I was asked for a regexp solution that would find all form field names in an HTML file and return only a list of the names with everything else removed.

Since I misunderstood the demand I first created a Lasso 9 solution. Turned out the need was for a Bbedit version. So, anyway, here's what I came up with:

Lasso 9:

var(myhtml = '
<form action="./" method="post">
	<input type="hidden" name="-action" value="myaction" />
			<label for="fname" id="fname_label">
				First Name
			<input type="text" name="fname" class="" id="fname" value="" size="30" />
			<label for="mname2" id="mname2_label">
				Middle Name
			<input type="text" name="mname" class="" id="mname2" value="" size="30" />
			<label for="record_title" id="record_title_label">
				Last Name *
			<input type="text" name="lname" class="" id="record_title" value="" size="30" />
			<label for="status12" id="status12_label">
				Status *
			<select name="status" class="" id="status12">
				<option value="Active" selected="selected">
				<option value="Inactive">
				<option value="Blocked">
	<input type="hidden" value="true" name="retries" />
	<input type="submit" name="button_add" class="button first" id="button_add21" value="Add" />
	<input type="submit" name="button_cancel" class="button cancel" id="button_cancel22" value="Cancel" />

var(myregexp = regexp(-find = ` name *= *("|')(.*?)("|')`, -input = $myhtml, -ignorecase))

var(myresult = array)
while($myregexp -> find) => {
	$myresult -> insert($myregexp -> matchstring(2))
$myresult -> join('\r')


Search for: ^(.*? name *= *)?(?(1)("|')(.*?)("|').*?(\r)|.*?\r)
Replace with. \3\5

Result in both:



Note that the Bbedit version will fail if there's more than one name value on a row. The Lasso 9 solution handles that fine.

Author: Jolle Carlestam
Created: 7 May 2012
Last Modified: 7 May 2012


No comments found
You must be logged in to comment.

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