For some reason this Go code works:
r := regexp.MustCompile("foo{bar}")
this seems strange since the "foo{bar}"
doesn’t seem like a valid regular expression ({
and }
) are not escaped.
On the contrary the equivalent Rust code (using regex
crate) fails with an error:
let r = regex::Regex::new("foo{bar}").unwrap();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex parse error:
foo{bar}
^
error: repetition quantifier expects a valid decimal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is this a feature of Go’s regexp
package to treat curly braces without valid repetition quantifiers literally, or am I missing something else?
New contributor
Eriks Harcevs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.