Reputation: 3378
For example, a file contains multiple strings, where some look like this:
--EX "ABCDEFG"
I created the following regular expression to see if the line matches:
^--EX\ \".*\"$
My question is now, can I somehow extract the content of .*
in order to just get ABCDEFG
?
Are regular expressions suitable for this?
Upvotes: 1
Views: 97
Reputation: 25763
Put parentheses around the part you want to get.
^--EX\ \"(.*)\"$
Then in whatever your code, it will be match 1, most implementations of regex imply match 0 is the full match, and match 1 will be the first set of parenthesis, and so on.
Upvotes: 2
Reputation: 1525
On the command line you must enter your command precisely as shown here:
sed -e "s/^--EX \"\(.*\)\"$/\\1/g" filename
Upvotes: 1
Reputation: 31182
you can get it via sed:
$ echo "--EX "ABCDEFG"" | sed 's/^--EX \(.*\)$/\1/'
ABCDEFG
Upvotes: 1