GNU sed does not have support for lookaround assertions. You could use a more powerful language such as Perl or possibly experiment with ssed
which supports Perl-style regular expressions.
perl -pe 's/(?<=foo)bar/test/g' file.txt
More Related Contents:
- Using sed and grep/egrep to search and replace
- Is it possible to escape regex metacharacters reliably with sed
- Non greedy (reluctant) regex matching in sed?
- How to find patterns across multiple lines using grep?
- Validating IPv4 addresses with regexp
- Regex (grep) for multi-line search needed [duplicate]
- RE error: illegal byte sequence on Mac OS X
- How do I grep for all non-ASCII characters?
- How can I output only captured groups with sed?
- Negative matching using grep (match lines that do not contain foo)
- (grep) Regex to match non-ASCII characters?
- Insert contents of a file after specific pattern match
- Using the star sign in grep
- How does the regular expression ‘(?
- How to extract string following a pattern with grep, regex or perl [duplicate]
- What’s the technical reason for “lookbehind assertion MUST be fixed length” in regex?
- What’s wrong with my lookahead regex in GNU sed?
- What does ‘\K’ mean in this regex?
- How can I insert a tab character with sed on OS X?
- Insert linefeed in sed (Mac OS X)
- Difference between egrep and grep
- Replace newlines with literal \n
- replace a unknown string between two known strings with sed
- Sed to extract text between two strings
- How do I use a new-line replacement in a BSD sed?
- How to change date format in sed?
- Replace all whitespace with a line break/paragraph mark to make a word list
- How to do a non-greedy match in grep?
- How to make “grep” read patterns from a file?
- Whats the difference between sed -E and sed -e