A regular expression meta-character is a character that contains special meanings. They have some special features that control how the pattern is matched. The metacharacters after the backslash loses its special meaning.
/ *using dot characters*/ varpattern =/g. gle/;//. Match an arbitrary character varstr = ' Google ';//g (here can be put to two in addition to the line break (\ n) any character, if there is only one point, then there is only one character)Alert (Pattern.test (str));//true /*repeat match*/ varpattern =/g.*gle/;//. * Indicates matching 0 one or more arbitrary characters o* means 0, 1 or more o varstr = ' Gbbbgle '; Alert (Pattern.test (str)); varpattern =/g.+gle/;//. + means matching at least one or more varstr = ' Gbbbgle '; Alert (Pattern.test (str)); varpattern =/g.? gle/;//.? Indicates a match of one or 0 varstr = ' Gbbbgle '; Alert (Pattern.test (str)); //false only one or 0 varpattern =/g.{2,4}gle/;//. {N,m} indicates a match N to M containing N and M varstr = ' Gbbbbgle '; Alert (Pattern.test (str)); varpattern =/g.{2}gle/;//. {n} indicates a match n is greater than or less than N is false varstr = ' Gbbbbgle '; Alert (Pattern.test (str)); varpattern =/g.{2,}gle/;//. {n,} means match n or more than n less than n is false varstr = ' Gbbbbgle '; Alert (Pattern.test (str));
/*using character class matching*/ varpattern= /G[a-za-z_]*gle/; //[a-z]* denotes any character in a-Z varStr= 'Google'; Alert (Pattern.test (str)); varpattern= /[A-z]oogle/; //[A-z] means that the first character matches to can be 26 lowercase letters can be matched, if you add I later can be ignored case varStr= 'Google'; Alert (Pattern.test (str)); varpattern= /[A-z]oogle/; //[A-z] means that the first character matches to can be 26 uppercase letters can be matched, if you add I later can be ignored case varStr= 'Google'; Alert (Pattern.test (str)); varpattern= /[0-9]oogle/; //[0-9] means that the first character matches to the number can be 0 to 9 can be matched, if the following add I can be ignored case varStr= '444oogle'; Alert (Pattern.test (str)); varpattern= /[0-9]*oogle/; //[0-9] means 0 times 1 times or multiple times can be 0 to 9 of the number can be matched, if you add I after the case can be ignored case varStr= '444oogle'; Alert (Pattern.test (str)); varpattern= /[0-9a-za-z]oogle/; //[0-9a-za-z] can be 0 to 9 between the number and the case of 26 letters can be matched, if you add I later can be ignored case varStr= '444oogle'; Alert (Pattern.test (str)); varpattern= /[^0-9a-z]oogle/; //[^0-9a-z] can match a number other than 0 to 9 and lowercase 26 letters can be matched, if you add I later can be ignored case varStr= '444oogle'; Alert (Pattern.test (str));
/*use anchor element character matching*/ varpattern= /^google$/; //^ match from beginning, $ start match from end varStr= 'Google'; Alert (Pattern.test (str)); varpattern= /^[0-9]oogle$/; //^ matches from the beginning if more than 4 is false varStr= '4oogle'; Alert (Pattern.test (str));
JavaScript Regular Expression _ get control