Home  >  Q&A  >  body text

javascript - js regular expression to get string

If there is a string like this " www.com.baidu.com "
What I want to match is all the strings after the first com, but excluding " com ", how should I write the regular expression? ? That is to say, the desired string is ".baidu.com"
It is best not to match it by capturing groups;

给我你的怀抱给我你的怀抱2681 days ago512

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-05-19 10:12:44

    var str = 'www.com.baidu.com'
    var result = /.*?com(.*)/.exec(str)
    console.log(result[1])

    reply
    0
  • 高洛峰

    高洛峰2017-05-19 10:12:44

    We are both newbies and have the same question.
    I guess before the text is taken out, set an intermediate state to accept the string width of the text, subtract the first 3, and then assign it to the calling one.
    (The above are all my guesses.)

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:12:44

    'www.com.baidu.com'.match(/.+\.com(.+)/)[1]
    // ".baidu.com"

    The regular diagram above:,

    reply
    0
  • Cancelreply