Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <2116422.PPeRs11RAM@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 14 Mar 2013 17:31:30 +0100 User-Agent: KNode/4.8.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+&. MIME-Version: 1.0 Lines: 54 NNTP-Posting-Date: 14 Mar 2013 17:31:31 CET NNTP-Posting-Host: 8ccbce5f.newsspool2.arcor-online.net X-Trace: DXC=EW?\2O@_]LcfF8a^:6>b7eA9EHlD;3Ycb4Fo<]lROoRa8kF I have this string in JavaScript: > > var s = "

  1. First\n
  2. Second\n

"; > > Then I do this (to remove the outer "

...

"): One wonders how it got there in the first place, since it is not Valid. One also wonders why you think you need to (or could, trivially) fix that. > s = s.replace(/^<\/([^> ]+)[^>]*>(.*)<\1>$/,"$2"); wrong This expression does _not_ accurately match HTML tags or elements, or XML tags or elements for that matter. See HTML5 (CR) and XHTML 1.0/1.1 (REC) for details. > Nothing happens (s is unchanged, and if I use match() instead of replace > it returns false), but if I go try it at > http://www.regular-expressions.info/javascriptexample.html, it works! > > I've tried all sorts of things (creating a separate regExp object, using > //g, taking out the ^$, replacing [^> ]+ with [a-z0-9]*...) but nothing > makes any difference. > > It's driving me nuts. Can anyone tell me what I'm doing wrong here? You are using “.” which does not match "\n", so that expression matches as far as

  1. First\n
  2. Second\n

`---'`-----------' : : : '-------. : : ,----------------.,--. ^<\/([^> ]+)[^>]*>(.*)<\1>$ (use a fixed-width font). Then it fails, because "\n" is not matched by “<”. That said, like so many other people before you, you are trying to apply an expression describing a Chomsky type-3 language to match a sentence of a text in a Chomsky type-2 language, which usually *must* fail. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.