Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function patternMatcher(str, regexp) {
- const regexpClone = new RegExp(
- regexp.source,
- regexp.flags ||
- (regexp.global ? 'g' : '') +
- (regexp.ignoreCase ? 'i' : '') +
- (regexp.multiline ? 'm' : '') +
- (regexp.dotAll ? 's' : '') +
- (regexp.unicode ? 'u' : '') +
- (regexp.sticky ? 'y' : '')
- )
- regexpClone.lastIndex = 0
- const matches = []
- let match
- if (regexpClone.global) {
- while(match = regexpClone.exec(str)) {
- matches.push(match)
- }
- }
- else {
- if (match = regexpClone.exec(str)) {
- matches.push(match)
- }
- }
- return matches
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement