0
<th>Prêmio</th>
    <td colspan="11">
    <div class="res"><img class="r1" src="img/x.gif" alt="Madeira" title="Madeira" />215 | <img class="r2" src="img/x.gif" alt="Barro" title="Barro" />193 | <img class="r3" src="img/x.gif" alt="Ferro" title="Ferro" />192 | <img class="r4" src="img/x.gif" alt="Cereal" title="Cereal" />202</div><div class="carry"><img class="car" src="img/x.gif" alt="carregamento" title="carregamento" />802/1800</div></td></tr></tbody></table><table cellpadding="1" cellspacing="1" class="defender">
    <thead>
    <tr>

i'm trying to get "802/1800", but it's driving me insane. if I use:

var myregexp = /title="carregamento"/;

it works

but going to the next step which is:

var myregexp = /title="carregamento" \/>/

already returs me null.

var myregexp = /title="carregamento" \/>/;

var match = myregexp.exec(document.documentElement.innerHTML);

FM_log(7,"match="+match);

if (match != null)
    resultado.push(match[1]);
2
  • It works for me.. Are you doing this in YQL or in a CDATA tag or something? The expression also works on RegexPal Commented May 17, 2010 at 18:29
  • No, i'm not. Still not working here. Commented May 17, 2010 at 20:25

3 Answers 3

1

You should probably post the exact code, because there may be something slight going wrong that's not exactly having to do with the regex object.

If I test this on regextester.com, it works perfectly.

I use the following regex, and it matches the string up to 802/1800, and selects 802/1800 into a capture group.

title="carregamento" \/>(\d+\/\d+)
Sign up to request clarification or add additional context in comments.

2 Comments

regextester.com works, but not if you use the correct sintax which is /title="carregamento" \/>(\d+\/\d+)/
the "/" characters that denote a string is a regex in javascript are not required. You only have to supply the actual regex string
1

The regexp you posted is correct:

var myregexp = /title="carregamento" />/

actually this one matches the string just before the "802/1800" string

Comments

0

Found what the problem was. Apparently there's a difference between what Firefox show me when I select "view document source" and what javascript is giving me as the source. Here's the difference:

firefox source:

<img class="car" src="img/x.gif" alt="carregamento" title="carregamento" />802/1800</div>

javascript source: (I created a LOG showing me document.documentElement.innerHTML

<img class="car" src="img/x.gif" alt="carregamento" title="carregamento">802/1800</div>

so the difference was a mere />

I also improved the code to:

        var myregexp = /title="carregamento">(.+?)\/(.+?)<\/div>/;


        FM_log(7,"myregexp="+myregexp);

        var resultado = [];

        var match = myregexp.exec(document.documentElement.innerHTML);

        //FM_log(7, document.documentElement.innerHTML);

        FM_log(7,"match="+match);

        if (match != null) {
            resultado.push(match[1])
            resultado.push(match[2])
            };

        FM_log(7,"resultado[0]="+resultado[0]+" resultado[1]="+resultado[1]);           

        efficiency = Math.round(resultado[0] / resultado[1] * 100);

        gain = resultado[0];

this is the final code and works perfectly.

Thanks for everyone who contributed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.