0

Hello everyone I have got following code:

<!--
            <li class="dropdown">
                <a href="#/score-board">Score Board</a>
                <a href="#/score-lol">Score lol</a>
                <a href="#/score-abcd">Score lolk</a>

            </li>
            -->

that I need to have a regex for

I have tried:

const regex = /(#.score([\s\S]*?).b([\s\S]*.?))/g;
const str = `<!--
            <li class="dropdown">
                <a href="#/score-board">Score Board</a>
                <a href="#/score-abc">Score Board</a>
                <a href="#/score-lol">Score Board</a>
            </li>
            -->`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }

    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}

I want instead to have following result
#/score-board

Could someone help me out?

Notice! the important is it fetch everything between " and "

Thank you in advance

ctwheels
  • 21,901
  • 9
  • 42
  • 77
  • `^<[\s\S]*?(score[-\w]+)[\s\S]*` or `href\s*=\s*["']?#\/(score[\w-]+)` then use code? – ctwheels Nov 30 '17 at 18:17
  • both the regex:s you send doesn't work it's fetches all. –  Nov 30 '17 at 18:21
  • 1
    The first one only gets the first result. The second result gets them all, but then you just need to say "get me the first one" or "get me the one that is score-board" – ctwheels Nov 30 '17 at 18:22
  • See https://stackoverflow.com/a/1732454/39321 – Svish Dec 01 '17 at 07:57

0 Answers0