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

hibernate - How to load global settings frequently used in application in Java -

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

objective c - Ownership modifiers with manual reference counting -