I'm reading this regex tutorial and it says:
The pattern to search for the word "the" would be "\<[tT]he>".
How come this doesn't output bar bar?
○ → echo "foo bar" | sed -E 's/\<foo\>/bar/'
foo bar
Can \< and \> be used in sed?
I'm reading this regex tutorial and it says:
The pattern to search for the word "the" would be "\<[tT]he>".
How come this doesn't output bar bar?
○ → echo "foo bar" | sed -E 's/\<foo\>/bar/'
foo bar
Can \< and \> be used in sed?
\< and \> are used for word boundaries but it is platform dependent.
On OSX sed you need to use [[:<:]] and [[:>:]] for the same:
echo "foo food bar" | sed -E 's/[[:<:]]foo[[:>:]]/bar/'
bar food bar
However if you can install gnu sed on OSX using brew package installer then you can use:
echo "foo food bar" | gsed -E 's/\bfoo\b/bar/'
bar food bar