zoukankan      html  css  js  c++  java
  • JS.match方法 正则表达式

    match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。

    该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置。

    <script type="text/javascript">
    var str="Hello world!"
    document.write(str.match("world") + "<br />")
    document.write(str.match("World") + "<br />")
    document.write(str.match("worlld") + "<br />")
    document.write(str.match("world!"))
    </script>

    输出

    world

    null

    null

    world!

    <script type="text/javascript">
    var str="1 plus 2 equal 3"
    document.write(str.match(/d+/g))
    </script>

    输出

    1,2,3(数组)

  • 相关阅读:
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    整体二分
    树链剖分+LCT
    上下界网络流
    莫队
    可并堆
    bzoj_1033: [ZJOI2008]杀蚂蚁antbuster
  • 原文地址:https://www.cnblogs.com/cnundefined/p/match.html
Copyright © 2011-2022 走看看