Platform Support for GNU Extensions to Basic Regular Expressions
Recently I was reviewing some shell script a colleague had written: if grep -e '@[^@]\+@' "$DIR/install.sh" ; then I thought the \ before the + was a mistake, and also pointed out that if + was to be used we’d probably need to pass -E for extended regular expression (ERE) support. The colleague replied that \+ in a basic regular expression (BRE) was the same as + in ERE (one or more repetitions). This was news to me! I wanted to know more, so I turned to the FreeBSD re_format(7) man page. Historically this is where most of my knowledge about the distinction between BREs and EREs came from. There was no mention of it there. I spun up a FreeBSD virtual machine and performed a quick test, which confirmed that \+ did in fact work.
Opening excerpt (first ~120 words) tap to expand
Platform Support for GNU Extensions to Basic Regular Expressions 28 June 2026 Recently I was reviewing some shell script a colleague had written: if grep -e '@[^@]\+@' "$DIR/install.sh" ; then I thought the \ before the + was a mistake, and also pointed out that if + was to be used we’d probably need to pass -E for extended regular expression (ERE) support. The colleague replied that \+ in a basic regular expression (BRE) was the same as + in ERE (one or more repetitions). This was news to me! I wanted to know more, so I turned to the FreeBSD re_format(7) man page. Historically this is where most of my knowledge about the distinction between BREs and EREs came from. There was no mention of it there.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at Wezm.