Prev: MBT shoes will shape up your body everyday
Next: FAQ Topic - My element is named myselect[], how do I access it? (2010-08-09)
From: Ry Nohryb on 9 Aug 2010 10:54 On Aug 9, 4:30 pm, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid> wrote: > Le 09/08/10 14:49, Ry Nohryb a écrit : > > > txt= 'some text plus [Dewhurst](Dewhurst, Stephen, C. "C++ Common > > Knowledge: Essential Intermediate Programming") plus some more text > > plus again [Dewhurst](Dewhurst, Stephen, C. "C++ Common Knowledge: > > Essential Intermediate Programming") plus even more text'; > > And what about (what I think OP wanted) : > > txt= 'some text plus [Dewhurst](Dewhurst, Stephen, C. "C++ Common > Knowledge: '+ > '\n\r' + > 'Essential Intermediate Programming") plus some more textplus again > [Dewhurst](Dewhurst, Stephen, C. "C++ Common Knowledge: Essential > Intermediate Programming") plus even more text'; > > ??? He has said: "I've already written code to find each markupLink and convert it to the desired HTML. The problem I have is putting it back into the paragraph.". I'm hoping the "find" includes line breaks... -- Jorge.
From: Lasse Reichstein Nielsen on 10 Aug 2010 01:15
Brett <bretttolbert(a)gmail.com> writes: > I've already written code to find each markupLink and convert it to > the desired HTML. The problem I have is putting it back into the > paragraph. If you have found it, you probably also have found the start position in the original string. In that case, replaceing the string match at position pos with something else is easily done as: string = string.substring(0, pos) + something_else + string.substring(pos + match.length); If you are doing multiple replacements, you shouldn't add the rest of the string and then start splitting it apart again, but instead work iteratively to add replacements and in-between text until you have processed the entire string. > I want to do a multi-line replace, replacing linkMarkup with > linkHtml. > > txt.replace(new RegExp(linkMarkup,'m'), linkHtml) doesn't work because > linkMarkup isn't a regexp pattern, it's just a string. Characters such > as the '++' in C++ need to be escaped. You don't really want/need to use the multiline flag. All it does is change the behavior of "^" and "$", which you don't use anyway. > Is there a way to convert a plain string into a regexp patter which > matches the plain string? Others have shown how to replace all special characters with escaped versions of themselves, but I wouldn't use RegExp for this. Even if you don't have the start position, you can still use string.indexOf(text) to find the text, and then use the string operations above. /L -- Lasse Reichstein Holst Nielsen 'Javascript frameworks is a disruptive technology' |