I’m dynamically making a regex.
I want it to match the following:
lem
le,,m
levm
lecm
Basically, “lem” but before the m it can have any number of , or any one of any character. Right now I have
le[\,]{0,}[.]?m
you can see it at
http://regexr.com?303ne
It should match every one but the third one.
Update: I figured it out:
le[\,]{0,}.?m
Whenever you think “or” in Regular Expressions, you should start with alternation:
matches either
aorb. Socan be translated quite literally to
where
...would be the list of characters to match (a character class). If you use that as part of a longer expression, you need to use parentheses, because concatenation binds stronger (has higher precedence) than alternation:Because the character class has only one item, we can simplify this:
Note that
.by default means “any character but newline”.