regex - Anchors inside of [ ] in sed -


using sed, why match:

sed 's/test$/pass/' <<< "test" 

...when doesn't?

sed 's/test[$]/pass/' <<< "test" 

because […] represents character class in regular expression, [$] matches single literal $ character.

in other words, cannot match anchors inside character classes. if want match a or b character or end of string, use alternation:

sed 's/test([ab]|$)/pass/' <<< "test" 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -