domi771
domi771

Reputation: 460

sed regex find and delete string globally

I have the following (working) regex:

UNUSED([^,}]+)\}|,\s?UNUSED([^{]+)|UNUSED([^{]+),\s?|UNUSED([^{]+)

I run the command

sed 's/UNUSED([^,}]+)\}|,\s?UNUSED([^{]+)|UNUSED([^{]+),\s?|UNUSED([^{]+)//g' < index.css > newfile

but the newfile still has all the patterns in which should have been removed. What I am doing wrong?

index.css incl. regex:

http://regexr.com/3agmm

Upvotes: 1

Views: 50

Answers (1)

hek2mgl
hek2mgl

Reputation: 158100

Your are using an extended POSIX regex. You you need to pass -r to sed to tell it to use extended POSIX regexes.

Also note that the capturing groups you are using can be omitted:

s/UNUSED[^,}]+}|,\s?UNUSED[^{]+|UNUSED[^{]+,\s?|UNUSED[^{]+//g

Of course you can also use a basic POSIX regex, then without the -n option:

s/UNUSED[^,}]\+}\|,\s?UNUSED[^{]\+\|UNUSED[^{]\+,\s?\|UNUSED[^{]\+//g

Upvotes: 5

Related Questions