Advertisement
Guest User

Untitled

a guest
May 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function patternMatcher(str, regexp) {
  2. const regexpClone = new RegExp(
  3. regexp.source,
  4. regexp.flags ||
  5. (regexp.global ? 'g' : '') +
  6. (regexp.ignoreCase ? 'i' : '') +
  7. (regexp.multiline ? 'm' : '') +
  8. (regexp.dotAll ? 's' : '') +
  9. (regexp.unicode ? 'u' : '') +
  10. (regexp.sticky ? 'y' : '')
  11. )
  12. regexpClone.lastIndex = 0
  13. const matches = []
  14. let match
  15. if (regexpClone.global) {
  16. while(match = regexpClone.exec(str)) {
  17. matches.push(match)
  18. }
  19. }
  20. else {
  21. if (match = regexpClone.exec(str)) {
  22. matches.push(match)
  23. }
  24. }
  25. return matches
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement