4 ms·
The point is not to have the best or most efficient regex expression, but rather to do the exercises and to highlight by this process misconceptions you may hav
by mekoka 15y ago
The point is not to have the best or most efficient regex expression, but rather to do the exercises and to highlight by this process misconceptions you may have about how the regex engine operates.
You enter what is given, you run it, see what the console returns, ponder about the implications for a few minutes and then scream "aha!"
What do you expect ^[0-9]+|[A-Z]+$ to return when matched against the various lines? What does it actually return? What conclusions do you draw from that little experiment?
- leeoniya 15y agounfortunately this is not an efficiency optimization. the intent appears to be to match EITHER all-alpha OR all-numeric strings. the regex, as given, would match both "&()ABC" and "5673%$^#" and "123ABC" but NOT "ABC123" what should be a simple concept is defeated and confusion ensues. the correct formulation should have been ^[0-9]+$|^[A-Z]+$ or (judging from the example input and output samples) [0-9]+|[A-Z]+
- zedshaw 15y agoUh, no, the intent is not to match all-alpha or all-numeric strings. It's to search for all alpha or all numeric. As I mentioned above, you're confusing search with match semantics.