I have a string:
const str = `abcde 9'2" abcde 8' abcde 7' 11" abcde`
I’m trying to extract these values:
[ "9'2", "8'", "7' 11" ]
I want to use regex groups to achieve this (my actual code is far more complex and regex groups will simplify things). But my regex is not quite working. Could someone assist to make all 3 tests return true in the code snippet below? many thx
const str = `abcde 9'2" abcde 8' abcde 7' 11" abcde`
const regex = /(d+' ?d+)"/g
const matches = [...str.matchAll(regex)]
const actual = matches.map(x => x[1])
const expected = [ "9'2", "8'", "7' 11" ]
console.log(actual) // [ "9'2", "7' 11" ]
// tests
console.log(actual[0] === expected[0]) // true
console.log(actual[1] === expected[1]) // false
console.log(actual[2] === expected[2]) // false