JavaScript regex match, search, replace, split 

Joined:
02/21/2009
Posts:
164

September 03, 2010 20:43:28    Last update: September 03, 2010 20:43:48
  • Match a regex:
    'Free online videos for $.10 each'.match(/each$/);
    // each
    

  • Search for a regex pattern:
    'Jack Jake Jason'.search(/son/);
    // 12
    

  • Replace by regex match:
    'Jack Jake Jason'.replace(/.a/g, 'Ma');
    // Mack Make Mason
    

  • Split by regex:
    'She sells seashells by the seashore'.split(/\s/);
    // [She,sells,seashells,by,the,seashore]
    

Share |
| Comment  | Tags