[thelist] How Do I Combine Two Regular Expressions into One?

Steve Cook sck at biljettpoolen.se
Thu Aug 31 01:49:03 CDT 2000


Hi James,

this seems to work for me...

function fnTrim(vStr) {
   return vStr.replace(/^\s*|\s*$/g,"");
}

The "pipe" separator is like an "OR" operator in the regex.

BTW - my JavaScript is so rusty that working out how to print the darn
results out to the page took me a few minutes :-) Dratted brackets!

.steve


----------------------------------
   WapWarp - http://wapwarp.com
 Wap-Dev - http://www.wap-dev.net
 Cookstour - http://cookstour.org
----------------------------------

> -----Original Message-----
> From: Aylard JA (James) [mailto:jaylard at equilon.com]
> Sent: den 30 augusti 2000 23:44
> To: Evolt List (E-mail)
> Subject: [thelist] How Do I Combine Two Regular Expressions into One?
> 
<SNIP>
> 
> function fnTrim(vStr) {
>    vStr = vStr.replace(/^\s*/g,"") ;
>    return vStr.replace(/\s*$/g,"") ;
> }
> 
> 	This provides the functionality of the VBScript Trim() 
> function, and
> then some, removing any leading or trailing whitespace characters. Can
> anyone show me how to combine these two statements? Thanks.
> 
> James Aylard




More information about the thelist mailing list