Skip to main content

Posts

Showing posts with the label Regex
var = /\A([aeiou]*)(.*)\z/.match("apple") This code regex will create an array with the first part is any length of vowel and the rest of the characters. var[0] = "apple" var[1] = "a" var[2] = "pple"

Regular Expression

These are the commonly used regular expression syntax. Basic Regex. 1. Input of literal will match whatever is inputted. It is case sensitive. For example /s/ will match all the 's' in cats , sands but will not match "S" in Superman. 2.   $ ^ * + ? . ( ) [ ] { } | \   The above are special characters , and must be escaped with a backslash. You can safely escape all special characters without errors. Spaces (" ") are not special characters , will be matched without backslash. 3.   /./ A period means any character. If you want to find "." only . Use backslash  /\./ 4. Regex will match any pattern you typed on it. If you typed /cat / it will match a "cat" followed by a space " " exactly. This is known as concatenation. The sequence of pattern matters. 5. If you want to choose one or the other,   /(cat|dog|rabbit)/   it will choose either cat , dog or rabbit. This is called Alternation. 6.  /launch/i If you want ...