Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. boy, man,girl, woman,tyrannosaurus rex, lion
  2.  
  3. hat, cat, rat, c3po, @gmail
  4.  
  5. /^w(s*,?s*w)*$/
  6.  
  7. /^s*w(s*,?s*w)*s*$/
  8.  
  9. /^s*[a-z0-9](s*,?s*[a-z0-9])*s*$/
  10.  
  11. /^s*([a-z0-9]+(s[a-z0-9]+)*)(s*,s*([a-z0-9]+(s[a-z0-9]+)*))*s*$/
  12.  
  13. var re = /^(w+,? ?)+$/;
  14. var str1 = "boy, man,girl, woman,tyrannosaurus rex, lion";
  15. var str2 = "hat, cat, rat, c3po, @gmail";
  16. alert(str1.test(re)); // true
  17. alert(str2.test(re)); // false
  18.  
  19. /^(w+s?[ws]*)(,s*w+s?[ws]*)*$/
  20.  
  21. Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
  22. Match the regular expression below and capture its match into backreference number 1 «(w+s?[ws]*)»
  23. Match a single character that is a “word character” (letters, digits, and underscores) «w+»
  24. Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
  25. Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «s?»
  26. Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
  27. Match a single character present in the list below «[ws]*»
  28. Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
  29. A word character (letters, digits, and underscores) «w»
  30. A whitespace character (spaces, tabs, and line breaks) «s»
  31. Match the regular expression below and capture its match into backreference number 2 «(,s*w+s?[ws]*)*»
  32. Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
  33. Note: You repeated the capturing group itself.
  34. The group will capture only the last iteration.
  35. Put a capturing group around the repeated group to capture all iterations. «*»
  36. Match the character “,” literally «,»
  37. Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «s*»
  38. Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
  39. Match a single character that is a “word character” (letters, digits, and underscores) «w+»
  40. Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
  41. Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «s?»
  42. Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
  43. Match a single character present in the list below «[ws]*»
  44. Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
  45. A word character (letters, digits, and underscores) «w»
  46. A whitespace character (spaces, tabs, and line breaks) «s»
  47. Assert position at the end of a line (at the end of the string or before a line break character) «$»
  48.  
  49.  
  50. Created with RegexBuddy
  51.  
  52. /^s*[a-z0-9]+(s+[a-z0-9]+)?(s*,s*[a-z0-9]+(s+[a-z0-9]+)?)*s*$/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement