Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18887
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: RegExp problem |
| Date | Thu, 14 Mar 2013 14:22:46 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 24 |
| Message-ID | <khsfbf$udt$1@dont-email.me> (permalink) |
| References | <9608f578-525d-4670-9792-0700df15eb41@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 14 Mar 2013 12:21:04 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="ad9d9996ed56b0226e850b84acbddfdf"; logging-data="31165"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nT9h1otZzPBl/JB66yuXs" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 |
| In-Reply-To | <9608f578-525d-4670-9792-0700df15eb41@googlegroups.com> |
| X-Antivirus-Status | Clean |
| X-Antivirus | avast! (VPS 130314-1, 14.03.2013), Outbound message |
| Cancel-Lock | sha1:zBkkPImyQVddCF3lHkzOdn6qusI= |
| Xref | csiph.com comp.lang.javascript:18887 |
Show key headers only | View raw
2013-03-14 13:56, John English wrote: > I have this string in JavaScript: > > var s = "</p><ol><li>First\n</li><li>Second\n</li></ol><p>"; > > Then I do this (to remove the outer "</p>...<p>"): > > s = s.replace(/^<\/([^> ]+)[^>]*>(.*)<\1>$/,"$2"); > > Nothing happens The period "." does not match newline characters, and the data string contains two newlines (\n). To work around this, replace (.*) by ((.|\n)*) Using regular expressions to process HTML fragments is generally clumsy and fragile. It might be better to operate on the DOM tree rather than serialized HTML. However, I don't quite see the point of this particular operation. Removing the optional </p> tag does not change document structure but may affect rendering due to browser bugs. -- Yucca, http://www.cs.tut.fi/~jkorpela/
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
RegExp problem John English <john.foreign@gmail.com> - 2013-03-14 04:56 -0700
Re: RegExp problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-03-14 14:22 +0200
Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 14:52 +0100
Re: RegExp problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-03-14 16:08 +0200
Re: RegExp problem Stefan Weiss <krewecherl@gmail.com> - 2013-03-14 15:25 +0100
Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 16:47 +0100
Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 21:11 +0100
Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 19:54 +0100
Re: RegExp problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-14 13:26 +0100
Re: RegExp problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-14 17:31 +0100
csiph-web