search

Home  >  Q&A  >  body text

javascript - About match()

alert('rgb(255)'.match(/rgb\((\d )\)/));

Looking for matches. I don’t understand why ["rgb(255)", "255"] is returned?

Why not just return "rgb(255)"

PHP中文网PHP中文网2817 days ago511

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-19 10:20:34

    Because you used capture, that is, the brackets.

    console.log('rgb(255)'.match(/rgb\((\d+)\)/));

    No need to capture it

    console.log('rgb(255)'.match(/rgb\(\d+\)/));

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:20:34

    For this kind of problem, please refer to the document directly: String.prototype.match()

    reply
    0
  • Cancelreply