Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

regular expression

New Here ,
Jun 20, 2007 Jun 20, 2007
Hello,

I need a little help with a regular expression. I would like to be able to find this string :

<!-- InstanceBeginEditable name="breadcrumb" -->

That is : a string beginning with "<!--" and containing as many white spaces as you wish, then "InstanceBeginEditable ", then as many white spaces as you wish, then "name=" ", then as many alphanumerical chars as you wish, then a quote, then as many white spaces as you wish and last "-->".

I'm trying to use this regular expression :

new RegExp("<!\-\-(\s)*InstanceBeginEditable(\s)*name=\"(\w)*\"(\s)*\-\->","g");

but as you can guess, it doesn't work.

A clue, anyone ?

TheGridOne
TOPICS
Extensions
403
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 20, 2007 Jun 20, 2007
When you use the string form of the RegExp constructor you need to escape the escapes (ie \\ ) because the first one applies to string escaping so the regexp thinks you're looking for w* (or a lot of w's). You can also create your regexp using the more natural looking format, which also make it easier to read. Here's two examples, both should match the same thing:

var myRegExp1 = new RegExp("<!--(\\s)*InstanceBeginEditable(\\s)*name=\"(\\w)*\"(\\s)*-->","g");
var myRegExp2 = /<!--(\s)*Instance...
Translate
Guest
Jun 20, 2007 Jun 20, 2007
When you use the string form of the RegExp constructor you need to escape the escapes (ie \\ ) because the first one applies to string escaping so the regexp thinks you're looking for w* (or a lot of w's). You can also create your regexp using the more natural looking format, which also make it easier to read. Here's two examples, both should match the same thing:

var myRegExp1 = new RegExp("<!--(\\s)*InstanceBeginEditable(\\s)*name=\"(\\w)*\"(\\s)*-->","g");
var myRegExp2 = /<!--(\s)*InstanceBeginEditable(\s)*name="(\w)*"(\s)*-->/g;

Chris
Adobe Dreamweaver Engineering
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2007 Jun 22, 2007
LATEST
Hello,

Yes, you're right. It all works now !

Thanx a lot,

theGridOne
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines