سؤال

I have these lines of code in a jquery textile parser:

 re = new RegExp('"\\b(.+?)\\(\\b(.+?)\\b\\)":([^\\s]+)','g');
 r = r.replace(re,'<a href="$3" title="$2">$1</a>');

 re = new RegExp('"\\b(.+?)\\b":([^\\s]+)','g');
 r = r.replace(re,'<a href="$2">$1</a>');

These lines of code search for strings like

 "hello this is an embedded link":http://www.google.com

And replace them with

 <a href="http://www.google.com">hello this is an embedded link</a>

However, the parser is unable to recognize strings with a period preceding the closing quotation marks:

 "This is also a link.":http://www.google.com

How can I change the regex on these lines to allow periods to precede the end quote? I can post more information and lines if it will help. I just have no idea how to write regexes..

هل كانت مفيدة؟

المحلول

Changing the

re = new RegExp('"\\b(.+?)\\b":([^\\s]+)','g');

to

re = /"(?!\s)([^"]*\S)":(\S+)/g;

should fix that.

Same changes could be applied to the first expression, like:

re = /"(?!\s)([^"()]+)\(([^"()]+)\)":(\S+)/g;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top