![]() So “” refers to all numerical digits while “” refers to all alphabetical characters whether they are lower case or upper case. If you have “”, then you’re looking for occurrences of 0, 1, 2, or 3.Ī hyphen (-) between two letters or characters means that any occurrence of a character between the two are a match. Similarly, “0123” means you are literally looking for “0123”. However, when the pattern is “”, you’re looking for occurrences “a”, “b”, or “c”. For example, if you have the pattern “abc”, then that means you’re literally looking for “abc”. A set expands the possibilities for making patterns, and represents exactly 1 character. Next, we’ll discuss sets created by brackets (). If you had the sentence “I’m departing from Miami at six o’clock” and the regex is “go|departing”, the match would be successful because even though “go” isn’t present, “departing” is. The vertical bar (|), much like in programming languages, represents “or”.All of these meta-characters follow the regex. You can also do braces () and in between you enter the specific number of occurrences you are looking for. No occurrence means that the match was unsuccessful. This means that as long as the pattern is matched at least once, a successful match has been made. The plus sign (+) checks for one or more occurrences of a pattern.So the strings “ab”, “abc”, and “abccc” all match the pattern. The “c” can occur or not and it’s will meet requirements. For example, if we had the pattern“abc*”, then as long as we have a string containing “ab” it will pass. This means that regardless of if the specific character, characters, or pattern actually occurs or not, it will always be a match. The asterisk (*) checks for zero or more occurrences of a pattern.The next couple of meta-characters refer to the number of times a regex occurs in a string. The dollar sign must always conclude the pattern. So taking the previous example, if the pattern is “tree$”, you will return a successful match since the word “tree” ends the string. On the opposite end of the spectrum, we have the dollar sign ($) which indicates the pattern must be at the end. ![]() The caret must be the first character of the pattern. So if you had the sentence “This looks like a tree” and you look for the pattern “^This” it will successfully match since “This” is in the beginning.
0 Comments
Leave a Reply. |