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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -