且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查字符串是否以标点符号开头(JavaScript)

更新时间:2023-11-26 19:17:22

使用正则表达式要简单得多.

using Regex is much simpler.

    var str = '.abc'
    var result = !!str.match(/^[.,:!?]/)

    console.log(result)

  • /表示正则表达式的开始/结束

    • / indicates start/end of Regular expression

      ^的意思是开始于"

      []表示字符集".它将匹配[]

      [] means 'character set'. it will match any characters between [ and ]

      此外,该应用程序对于学习正则表达式非常有用! http://regexr.com/

      Additionally, this app is quite good to learn Regex! http://regexr.com/

      祝您有美好的一天! :D

      Have a nice day! :D