This works:
sed -rne 's/(dbservername)\s+\w+/\1 yyy/gip'
(When you use the -r option, you don’t have to escape the parens.)
Bit of explanation:
-ris extended regular expressions – makes a difference to how the regex is written.-ndoes not print unless specified –sedprints by default otherwise,-emeans what follows it is an expression. Let’s break the expression down:s///is the command for search-replace, and what’s between the first pair is the regex to match, and the second pair the replacement,gip, which follows the search replace command;gmeans global, i.e., every match instead of just the first will be replaced in a line;iis case-insensitivity;pmeans print when done (remember the-nflag from earlier!),- The brackets represent a match part, which will come up later. So
dbservernameis the first match part, \sis whitespace,+means one or more (vs*, zero or more) occurrences,\wis a word, that is any letter, digit or underscore,\1is a special expression for GNUsedthat prints the first bracketed match in the accompanying search.