. means any character that isn’t a newline (
\n). In this text,
"The core of it is,"
"a cur can't drive a car",
c.r matches the
'cur', and the
\w is the word character, which is all letters, digits, and the underscore (
00:58 All of the backslash meta-characters support capitalization being the inverse. The regex on the left has three word letters, followed by a non-word letter, followed by a digit. This matches the model numbers on the right-hand side.
\s is the meta-character for whitespace. Literal
ark followed by a
'ark wa' and
'ark an' in
'The ark was large.' and
'Inside it was dark and scary.' To match a backslash character, you need to escape it with another backslash character.
02:41 You can also change the behavior of the regex by putting it in multiline mode. Multiline mode changes whether or not a newline is considered the beginning of an anchor match. By default, it’s only the beginning and end of the string. In multiline mode, it’s the beginning, the end, and any newline, allowing you to treat paragraph breaks as if they are the beginning of new strings.
03:15 You may remember that the caret symbol inside of square brackets negates the square brackets. Unfortunately, although it’s a little confusing, a caret also means something completely different outside of the square brackets—it means anchoring to the beginning of the string.
'Product' is matched. This is because in multiline mode, anchors match to the beginning of paragraphs, so if the line before ends in a carriage return, it’s considered like the beginning of the string. This is pretty useful if you’re doing multiline texts like this.
Remember, that period (
.) itself is a meta-character, so to match a period I have to escape it. And the
$ says “at the end of a line.” Because I’m in multiline mode, this is matching the end of the sentences.
Become a Member to join the conversation.