02-Two core methods of regularization

There are two core methods in regular expressions:

1) test verification verifies whether our string complies with the rule of regular expression

Syntax: reg.test (the string you want to test)
Return value: one is a boolean type true conforms to the rule false does not conform to the rule
Insert picture description here

2) exec capture gets a string that meets our rules from a string.
Syntax: reg.exec (the string you want to capture)
Return value:
null: If the string I want to capture does not appear in the original string, Then return a null
array: [0] is the captured fragment (no matter how many fragments you have, the first fragment is captured; no matter how many times you capture, the first fragment is also captured)
Insert picture description here

Guess you like

Origin blog.csdn.net/QZ9420/article/details/113356450