Reputation: 41
I have a large text from which I want to extract data according to a specific scheme.
Scheme:
(something) something (something|something)
for example
(Point A) 147 (-10|22) or (City) 479 (147|-20)
There are many such phrases in my text and I would like to write each one to array.
Upvotes: 1
Views: 79
Reputation: 31805
This regexp should do the trick for you:
const input = 'Some other text (City) 479 (147|-20) Some other text';
const result = /\(\s*([^)]*)\s*\)\s*([^(]*)\s*\(\s*([^|]*)\s*\|\s*([^)]*)\s*\)/g.exec(input);
console.log(result);
Upvotes: 1