1

Under Solaris 5.10, Why this regexp doesn't match a line like tag="12447"

 sed  "s/tag=\"[0-9]+\"/emptytag/" test.xml

(I noticed that -r is not implemented in the sed version)

Stef
  • 3,691
  • 6
  • 43
  • 58

1 Answers1

2

In strict posix mode, the + sign cannot be used to represent "one or more" of something. You can use a range of {1,} instead (escaped of course):

echo 'tag="12447"' | sed --posix "s/tag=\"[0-9]\{1,\}\"/emptytag/"
emptytag

Note that you don't actually need the --posix, I was just using it to disable all GNU extensions in my version of sed:

echo 'tag="12447"' | sed "s/tag=\"[0-9]\{1,\}\"/emptytag/"
emptytag
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141