How to use the matchChain function from xregexp

Find comprehensive JavaScript xregexp.matchChain code examples handpicked from public code repositorys.

53
54
55
56
57
58
59
60
61
62
// Extract every other digit from a string using XRegExp.forEach
XRegExp.forEach('1a2345', /\d/, function(match, i) {
    if (i % 2) this.push(+match[0]);
}, []); // -> [2, 4]

// Get numbers within <b> tags using XRegExp.matchChain
XRegExp.matchChain('1 <b>2</b> 3 <b>4 a 56</b>', [
    XRegExp('(?is)<b>.*?</b>'),
    /\d+/
]); // -> ['2', '4', '56']
fork icon90
star icon165
watch icon25

46
47
48
49
50
51
52
53
54
55
console.log(evens); // evens -> [2, 4]


// Get numbers within <b> tags using XRegExp.matchChain
// mathChain returns an array (global style)
result = XRegExp.matchChain('1 <B>2</B> 3 <b>4 a\n56</b>', [
    XRegExp('(?is)<b>.*?</b>'), // options (?is) inside XRegExp i= ignore case s=  . matches every character 
    /\d+/
]);
console.log(result); // -> ['2', '4', '56']
fork icon1
star icon0
watch icon2

+ 7 other calls in file