I would like to split a string base on regex.
Expected input:
1. recipe description. 2. second step of the description that takes 30 minutes. 3. third step of the description that contain 20g of flour.
Now like to split the string based on the starting number. Is that possible?
Expected outcome:
[
"recipe description.",
"second step of the description that takes 30 minutes.",
"third step of the description that contain 20g of flour."
]
I already tried it with const steps = text.split(new RegExp("/^d./", "g")); but its not the expected outcome i would like to have.
.is any character regexper.com/#%2F%5Ed.%2Fg and your code will have problems when you reach 10 steps once you fix the problems.new RegExp()here. You're also not escaping the.character, nor are you escaping a \ character for your\dinput. Just use/\d\./gdirectly. Also, think about using sites like regex101 or regexr to actually know what you're writing.