tags:

views:

48

answers:

4

Hi There,

I have some markup which contains the firebug hidden div. (long story short, the YUI RTE posts content back that includes the hidden firebug div is that is active)

So, in my posted content I have the extra div which I will remove server side in PHP:

<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div>

I cant seem to get a handle on the regex I would need to write to match this string, bearing in mind that it won't always be that exact string (version may change).

All help welcome!

+2  A: 

Regex is not the best tool for the job, but you can try:

<div firebugversion=[^>]*></div>

The […] is a character class. Something like [aeiou] matches one of any of the lowercase vowels. [^…] is a negated character class. [^aeiou] matches one of anything but the lowercase vowels.

The * is the zero-or-more repetition. Thus, [^>]* matches a sequence of anything but >.

If you want to target the id specifically, you can try:

<div [^>]*\bid="_firebugConsole"[^>]*></div>

The \b is the word boundary anchor.

polygenelubricants
+1  A: 

I would suggest this:

 \<div firebugversion="(.+)" style="(.+)" id="(.+)"\>

Then you have three groups:

  1. firebugversion
  2. style
  3. id
schoetbi
`<` and `>` need no escaping.
Bart Kiers
+1  A: 

Match this regex -

<div.*id="_firebugConsole".*?/div>
Gopi
+1  A: 

This one is a little more complicated, and probably not perfect, but it will:

  • Match any div containing the attribute firebugversion
  • Match the firebugversion attribute no matter which order attributes appear in the tag
  • Match the div, even if it contains content or spacing between it and its closing tag (i've seen the firebug tag with a &nbsp ; tag inside it before) Note: it does lazy matching so it will only match the next tag, rather than the last it finds in the document

<(div)\b([^>]*?)(firebugversion)([^>]*?)>(.*?)</div>

Nick