I've been told to use this regex with sed:
sed 's/^.*=\([^=]*\)=.*=.*$/\1/'
to get the PATH part from:
NAME=PATH=USER=DATE
If I "read" the regex i would say something like: From the beginning of the line (^
),any character any number of times (.*
) and then an equal sign (=
). There I would have gotten just NAME=
. What I don't understand is what to read next, the \( \)
part.
I've seen this multiple times and I know it has something to do with the /\1
at the end of the expression but I don't quite get it.
The other part (=.*=.*$
) would be: from an equal sign (=
) any character any number of times (.*
) until it reads an equal (=
) and again, any character until reaching end of line ($
).