Discussion:
Differences between BRE and ERE in syntactic behavior of quantifiers (gnu sed 4.2.1)
gilles_arcas@hotmail.com [sed-users]
2014-08-14 19:12:10 UTC
Permalink
Following a previous discussion, I would like to report some BRE/ERE differences for ill-formed regexp including quantifiers.* Quantifier at start of regexp (i.e. following an empty regexp)For instance: echo x | sed -e "/*/p"BRE: this is valid syntax for *, ? and +, but invalid for {}ERE: always invalid* Double quantifierFor instance: echo x | sed -e "/x**/p"BRE: whatever quantifier is in first position, this is valid syntax when ? or + is in second position, invalid when * or {} is in second positionERE: always validIt is confusing to have different behaviors not only between BRE and ERE, but also between quantifiers. This could deserve some clarification.Would there be any drawback to consider these expressions equivalent to /()q/ and /(xq)q'/ for any quantifier q and q', which are valid
in all cases?


[Non-text portions of this message have been removed]
Daniel Goldman dgoldman@ehdp.com [sed-users]
2014-08-15 16:29:34 UTC
Permalink
That is useful research you did, as an addition to the previous
discussion about BRE/ERE differences with ^ and $ literals.


s/*/Hello/ does not work under ERE as you point out, I did not know that
before. s/\*/Hello/ works correctly with BRE and ERE. The downside is
the \ backslash and "leaning toothpick syndrome". At least we can
alternatively use s:\*:Hello:


I agree the BRE / ERE differences are confusing. I'm not sure the best
way to resolve this in the sed program and docs, even assuming a change
was possible. Maybe ERE is "correct behavior", because * IS supposed to
follow something. Or maybe BRE is "correct behavior", because it
protects the user and "figures out" that a literal was meant.


What I do is always use the \* form when I want a literal, that way no
confusion, removes ambiguity, and both BRE and ERE work.


Daniel
Post by ***@hotmail.com [sed-users]
Following a previous discussion, I would like to report some BRE/ERE differences for ill-formed regexp including quantifiers.* Quantifier at start of regexp (i.e. following an empty regexp)For instance: echo x | sed -e "/*/p"BRE: this is valid syntax for *, ? and +, but invalid for {}ERE: always invalid* Double quantifierFor instance: echo x | sed -e "/x**/p"BRE: whatever quantifier is in first position, this is valid syntax when ? or + is in second position, invalid when * or {} is in second positionERE: always validIt is confusing to have different behaviors not only between BRE and ERE, but also between quantifiers. This could deserve some clarification.Would there be any drawback to consider these expressions equivalent to /()q/ and /(xq)q'/ for any quantifier q and q', which are val
id in all cases?
Post by ***@hotmail.com [sed-users]
[Non-text portions of this message have been removed]
------------------------------------
------------------------------------
Loading...