I am not an expert at regular expression and have a regular expression
^\s?([-*]|\d+[.])\s+
I wonder if anyone has ideas about shortening/optimizing/simplifying the above regular expression?
I am not an expert at regular expression and have a regular expression
^\s?([-*]|\d+[.])\s+
I wonder if anyone has ideas about shortening/optimizing/simplifying the above regular expression?
As Regexes go, that one is pretty darn short and simple as it is. Does it work as you expect? If so, leave it alone.
Why would you want to optimize it? The contents of your regular expressions are already made of nonredundant atoms. You cannot simplify this more…
You can save one entire character (yay!) by writing:
^\s?([-*]|\d+\.)\s+
Other than that there's not much to do here. If you don't need the contents of the alternation, you could make the group non-capturing and maybe shave a nanosecond or two off by writing
^\s?(?:[-*]|\d+\.)\s+
but that's very probably the most extreme form of premature optimization you can do. Plus, you need more characters...