FG

use of alternation "|" in sed's regex

Fresh3 days ago
Mar 15, 2026109941 views
Confidence Score1%
1%

Problem

I am using sed, GNU sed version 4.2.1. I want to use the alternation "|" symbol in a subexpression. For example : should return but it returns How can I have the expected result ?

Error Output

echo "blia blib bou blf" | sed 's/bl\(ia|f\)//g'

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: use of alternation "|" in sed's regex

Low Risk

The "|" also needs a backslash to get its special meaning. will do what you want. As you know, if all else fails, read the manual :-). GNU sed user's manual, section 3.3 Overview of Regular Expression Syntax: `REGEXP1\|REGEXP2' Matches either REGEXP1 or REGEXP2. Note the backslash... Unfortunately, regex syntax is not really standardized... there are many variants, which differ among other things in which "special characters" need \ and which do not. In some it's even configurable or depends on…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment