Convert Regex w look behind to safari compatible regex

28 Views Asked by At

Safari lol.

Any regex guru's that could help please. I have a recipes with ingredient lists that need to be broken down into each ingredient. I'm currently using the below regex:

/(?<!\d)\s(?=(?<!x)\d(?![x]))/gm

but Safari is trash and doesn't support look behinds. If anyone could provide an alternative that would work in Safari it would be much appreciated!

here's a sample of text:

1 cup water 1 Tablespoon salt 1 stick (4 oz) butter 1 cup flour 4 eggs 1 small head cauliflower (1 1/2 lbs), cut in 1" florets 10 salted anchovies, filleted, rinse twice (opt) 2 quarts olive oil, heat to 375F

Tried look behinds in regex.

1

There are 1 best solutions below

0
Tim Biegeleisen On

I would approach this with a regex find all:

var input = "1 cup water 1 Tablespoon salt 1 stick (4 oz) butter 1 cup flour 4 eggs 1 small head cauliflower (1 1/2 lbs), cut in 1\" florets 10 salted anchovies, filleted, rinse twice (opt) 2 quarts olive oil, heat to 375F";
var ingredients = input.match(/\b\d+(?: \S+)*?(?= \d+ |$)/g);
console.log(ingredients);