This is an extension notation (a '?' following a '(' is not meaningful otherwise). To match the literals '(' or ')', use \( or \), or enclose them inside a character class:. Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. This can be used inside groups (see below) as well. An arbitrary number of REs can be separated by the '|' in this way. For example, b] will both match a parenthesis.Ī|B, where A and B can be arbitrary REs, creates a regular expression that will match either A or B. Specifies that exactly m copies of the previous RE should be matched fewer matches cause the entire RE not to match.
Adding ? after the qualifier makes it perform the match in non-greedy or minimal fashion as few characters as possible will be matched. Sometimes this behaviour isn’t desired if the RE is matched against ' b ', it will match the entire string, and not just ''. The '*', '+', and '?' qualifiers are all greedy they match as much text as possible. For example, /r?eu?/ matches the 're' in "w3resource" and the 'eu' in "europe". Matches the previous character 0 or 1 time. For example, /a+/ matches the 'a' in "Daniel" and all the a's in "Daaam" Matches the previous character 1 or more times. For example, /bo*/ matches 'boo' in "A bootable usb" and 'b' in "A beautiful mind", but nothing in "A going concern". Matches the previous character 0 or more times. (Caret.) Matches the beginning of the string or line.įor example /^A/ does not match the 'A' in "about Articles" but does match it in "Articles of life"įor example, /e$/ does not match the 't' in "exact", but does match it in "w3resource".
If the DOTALL flag has been specified, this matches any character including a newline. (Dot.) In the default mode, this matches any character except a newline.