Guest User

Untitled

a guest
Jul 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. //if match
  2. if (subject.match(/abc/)) {
  3. // Successful match
  4. } else {
  5. // Match attempt failed
  6. }
  7.  
  8.  
  9. //get all match
  10. result = subject.match(/regex/g);
  11.  
  12. //object match test
  13. var myregexp = /regex/i;
  14. var match = myregexp.exec(subject);
  15. if (match != null) {
  16. // matched text: match[0]
  17. // match start: match.index
  18. // capturing group n: match[n]
  19. } else {
  20. // Match attempt failed
  21. }
  22.  
  23. //iterate over all match in a string
  24. var match = myregexp.exec(subject);
  25. while (match != null) {
  26. // matched text: match[0]
  27. // match start: match.index
  28. // capturing group n: match[n]
  29. match = myregexp.exec(subject);
  30. }
  31.  
  32. //iterate over all matches and capturing groups in a string
  33. var myregexp = /regex/ig;
  34. var match = myregexp.exec(subject);
  35. while (match != null) {
  36. for (var i = 0; i < match.length; i++) {
  37. // matched text: match[i]
  38. }
  39. match = myregexp.exec(subject);
  40. }
Add Comment
Please, Sign In to add comment