
The regex matches the literal string "3.2" as long as it is found at the end of the string Let's give it a try: // The metacharacter $ indicates that we look for a match at the end of the string. The dollar metacharacter indicates end of the string The caret metacharacter indicates the start of the string

The dot metacharacter matches any character except for a new line Let's learn our first 3 metacharacters: The metacharacter Metacharacters are characters that have special meaning in regular expressions. If we change the string to something that doesn't match the pattern, preg_match will return false. Preg_match searches for a string that matches the regular expression ( $regex) in the string ( $string),Īnd the first match it finds is stored as the first item of the $match array. We found a match to to the expression: go $string = "you gotta give the go kart a try" Įcho "We found a match to the expression: ". We search for a match inside this string. ( preg_match stops searching as soon as it finds the first match).įor example:
If it finds a match, it returns true, otherwise it returns false.

Preg_match is built-in PHP function, that searches for a match to regular expressions within strings.
