-1

I wont to remove this,

I tried this How do I match any character across multiple lines in a regular expression?. but didn't work.

<span> powered by </span>
<a
 href="http://keystonejs.com"
 target="_blank"
 className={css(classes.link)}
 tabIndex="-1"
>
 KeystoneJS
</a>

const string = `
        tabIndex="-1"
                        className={css(classes.link)}
                    >
                        {brand + (appversion ? (' ' + appversion) : '')}
                    </a>
                    <span> powered by </span>
                    <a
                        href="http://keystonejs.com"
                        target="_blank"
                        className={css(classes.link)}
                        tabIndex="-1"
                    >
                        KeystoneJS
                    </a>
                    <span> version {version}.</span>
                    {this.renderUser()}
`;

console.log(string.match(/<span>\spowered(.*)<\/a>/gmi));
dinindu
  • 3,100
  • 1
  • 19
  • 35
  • Dot doesn't match new lines by default. Also, in general you probably [don't want to match HTML using regex](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). Why not parse it and directly remove the node? – VLAZ Oct 22 '20 at 16:37
  • 1
    `s` flag [works for me](https://tio.run/##rVLBToNAEL3zFRMuLJou8WZaqGc18WK8NbEDjECBXbKzQRvSb0dsUZMGjDHOafZldubNe7PDFjkxRWMX7XXfJ1qxBbamUBlEsHVgDIvxrUrpLXIXV@4Xeh5JhcwPWFPUJczi@CSWVaFK/zD5az3bq4sNqhQuQWDTtGS40ApuQHjgDeA35sMSPG@mfRjg9ISQG1RraPQrGUoh3g@lR2i6Gmdp5oZeIje3tlkGQUl7tlrRjmWi63mdLJqMbOQ@xxWq8j/1/J1X86rfjxvcPf5Jz0@fujE5yJ9k7WxesDQ0kDVPTEYMS21XjvNxhboiWelMnG5R1miTXASnMRsefRPywg83A6cg48L3V33/Dg). – Ryszard Czech Oct 23 '20 at 21:26

1 Answers1

-1

This works

string.match(/<span>\spowered(.|\n)*<\/a>/gim)

Your code doesn't work because . doesn't match new lines