How do I make a regex that optionally matches a word in a string? For example, let’s say I have a regex to match the sentence:
I like vanilla ice cream.
but I want that “vanilla” word to be optional so the same regex also matches
I like ice cream.
How do I do it? I’ve been using (vanilla)? but that doesn’t seem to be working.
Not only does the word
vanillaneed to be optional, but also the white space that follows, i.e.,(vanilla )?: