In a couple recent questions here on Stack Overflow, I've seen the regex sequence .{1}
. In the regex engines with which I'm familiar, a repeat count of 1 is strictly redundant.
Is there a regex engine that I am unaware of for which this is not true?
Could this explicit count of 1 be an attempt to comment/highlight that the preceding .
is a metacharacter?
I'm just trying to understand the motivations for this practice.
Links: Regex with $ anchor and look ahead is the most recent... looking for the other...
Putting {1}
after any repeatable term has no effect whatsoever.
I could understand if {1}
appeared in a regex that was generated using a variable for the count of a term, eg:
String regex = "foo.{" + n + "}bar";
to match "foo"
and "bar"
separated by n
characters. When n
happened to be 1
, you would get "foo.{1}bar"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With