Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20978
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <2064695.sT4V1ypfN8@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sun, 18 Aug 2013 10:57:18 +0200 |
| User-Agent | KNode/4.10.5 |
| Content-Transfer-Encoding | 8Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: textarea multi-line regex |
| Newsgroups | comp.lang.javascript |
| References | <kunrtr$bdr$1@dont-email.me> <520f7647$0$6638$9b4e6d93@newsspool2.arcor-online.net> |
| MIME-Version | 1.0 |
| Lines | 55 |
| NNTP-Posting-Date | 18 Aug 2013 10:57:27 CEST |
| NNTP-Posting-Host | dc181f7b.newsspool2.arcor-online.net |
| X-Trace | DXC=`]3oC<lA;ghOKO]LCQ@0g`A9EHlD;3Ycb4Fo<]lROoRa8kF<OcfhCOk4LhWYJTITMlDZm8W4\YJNlERkIik_S4^iF91Hd0][2JcJe8B?A9`MOk |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:20978 |
Show key headers only | View raw
Martin Honnen wrote:
> I think the "." dot does not match the "\n" character.
Correct.
> If you want to trim leading and trailing white space can't you simply use
> string = string.replace(/^\s+|\s+$/g, '')
string = string.replace(/^\s+/, '').replace(/\s+$/, '');
might be more efficient:
<http://blog.stevenlevithan.com/archives/faster-trim-javascript>
ECMAScript Edition 5 introduces String.prototype.trim():
string = string.trim();
<http://PointedEars.de/es-matrix/?filter=trim>
<http://ecma-international.org/ecma-262/5.1/#sec-15.5.4.20>
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim>
The following pattern appears to be useful:
string = (typeof string.trim == "function"
? string.trim()
: string.replace(/^\s+/, '').replace(/\s+$/, ''));
You may want to emulate the “trim” method if you cannot be sure it is
implemented, and you need to trim more than one time:
if (typeof String.prototype.trim != "function")
{
String.prototype.trim = function () {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
}
// …
string = string.trim();
(Emulations backwards compatible to the earliest versions of ECMAScript
implementations, and beyond, are also conceivable.)
> ? See also http://jibbering.com/faq/#trimString.
An update there is indicated.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
textarea multi-line regex Denis McMahon <denismfmcmahon@gmail.com> - 2013-08-17 12:56 +0000
Re: textarea multi-line regex Martin Honnen <mahotrash@yahoo.de> - 2013-08-17 15:10 +0200
Re: textarea multi-line regex "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-08-17 17:13 +0200
Re: textarea multi-line regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 10:57 +0200
Re: textarea multi-line regex "Joao Rodrigues (J.R.)" <groups_jr-1@yahoo.com.br> - 2013-08-19 11:04 -0300
Re: textarea multi-line regex Denis McMahon <denismfmcmahon@gmail.com> - 2013-08-17 13:18 +0000
Re: textarea multi-line regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 10:29 +0200
Re: textarea multi-line regex Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-08-18 19:24 +0100
Re: textarea multi-line regex "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-08-18 23:11 +0200
Re: textarea multi-line regex Denis McMahon <denismfmcmahon@gmail.com> - 2013-08-18 21:36 +0000
Re: textarea multi-line regex "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-08-19 00:50 +0200
Re: textarea multi-line regex Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-08-19 19:48 +0100
Re: textarea multi-line regex Stefan Weiss <krewecherl@gmail.com> - 2013-08-19 00:18 +0200
Re: textarea multi-line regex Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 10:22 +0200
csiph-web