sashomaga

Regex

Jul 30th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         var str = "abla  mla  atra  lala baaaaaaaaba";
  2.         var re = /[a-z]{2,4}/g;
  3.         var matches = str.match(re);
  4.  
  5.         // var re = new RegExp("\\w+") (same as) /\w+/
  6.  
  7.         // ^ begin of string or NOT [^a]
  8.         // $ end of string
  9.  
  10.         // g -> (after ending slash) gives all matches (without g only first one)
  11.         // i -> (after ending slash) ignore case
  12.  
  13.         // () -> grouping
  14.         // {n} exactly n occurrences of preceding item
  15.         // {n,} n occurrences or more occurrences of preceding item
  16.         // {n,m} n <-> m interval of occurrences of preceding item
  17.  
  18.         // \w -> [A-Za-z0-9_]
  19.         // \s -> single whitespace
  20.         // \b -> boundary between space and letter (wrap word)
  21.         //var re = /\b\w*[a{3}]+\b/g;
  22.        
  23.        
  24.         // * -> 0 or more matches of preceding item
  25.         // + -> 1 or more matches of preceding item
  26.         // ? -> 0 or 1 matches of preceding item
  27.         // . -> 1 any char
  28.  
  29.         // x|y -> or
Advertisement
Add Comment
Please, Sign In to add comment