正则表达式 regular expression

来源:互联网 发布:淘宝卖家怎么赚淘金币 编辑:程序博客网 时间:2024/06/10 07:35

/ is the start of the regular expression.
the is the pattern we want to match.
/ is the end of the regular expression.
g means global, which causes the pattern to return all matches in the string, not just the first one.
i means that we want to ignore the case (uppercase or lowercase) when searching for the pattern.
\d is used to retrieve one digit (e.g. numbers 0 to 9) in a string.+ after the selector, e.g.
/\d+/g, allows this regular expression to match one or more digits.
\s to find whitespace
\S will match anything that isn’t whitespace.(with no ‘+’)
\r the carriage return
\n newline
\t tab
\f the form feed

regexObj.test(str):
var str = 'hello world!';var result = /^hello/.test(str);console.log(result); // true
原创粉丝点击