sed: regexp extensions
1
1 5.6 regular expression extensions
1 =================================
1
1 The following sequences have special meaning inside regular expressions
1 (used in ⇒addresses Regexp Addresses. and the 's' command).
1
DONTPRINTYET 1 These can be used in both ⇒basic BRE syntax. and *note1DONTPRINTYET 1 These can be used in both ⇒basic BRE syntax. and ⇒
extended ERE syntax. regular expressions (that is, with or without the
1 '-E'/'-r' options).
1
1 '\w'
1 Matches any "word" character. A "word" character is any letter or
1 digit or the underscore character.
1
1 $ echo "abc %-= def." | sed 's/\w/X/g'
1 XXX %-= XXX.
1
1 '\W'
1 Matches any "non-word" character.
1
1 $ echo "abc %-= def." | sed 's/\W/X/g'
1 abcXXXXXdefX
1
1 '\b'
1 Matches a word boundary; that is it matches if the character to the
1 left is a "word" character and the character to the right is a
1 "non-word" character, or vice-versa.
1
1 $ echo "abc %-= def." | sed 's/\b/X/g'
1 XabcX %-= XdefX.
1
1 '\B'
1 Matches everywhere but on a word boundary; that is it matches if
1 the character to the left and the character to the right are either
1 both "word" characters or both "non-word" characters.
1
1 $ echo "abc %-= def." | sed 's/\B/X/g'
1 aXbXc X%X-X=X dXeXf.X
1
1 '\s'
1 Matches whitespace characters (spaces and tabs). Newlines embedded
1 in the pattern/hold spaces will also match:
1
1 $ echo "abc %-= def." | sed 's/\s/X/g'
1 abcX%-=Xdef.
1
1 '\S'
1 Matches non-whitespace characters.
1
1 $ echo "abc %-= def." | sed 's/\S/X/g'
1 XXX XXX XXXX
1
1 '\<'
1 Matches the beginning of a word.
1
1 $ echo "abc %-= def." | sed 's/\</X/g'
1 Xabc %-= Xdef.
1
1 '\>'
1 Matches the end of a word.
1
1 $ echo "abc %-= def." | sed 's/\>/X/g'
1 abcX %-= defX.
1
1 '\`'
1 Matches only at the start of pattern space. This is different from
1 '^' in multi-line mode.
1
1 Compare the following two examples:
1
1 $ printf "a\nb\nc\n" | sed 'N;N;s/^/X/gm'
1 Xa
1 Xb
1 Xc
1
1 $ printf "a\nb\nc\n" | sed 'N;N;s/\`/X/gm'
1 Xa
1 b
1 c
1
1 '\''
1 Matches only at the end of pattern space. This is different from
1 '$' in multi-line mode.
1