In GNU awk, which will be:
$ cat tst.awk BEGIN { str = "foo=23" val = gensub(/foo=([0-9]+)/,"\\1","",str) print "foo value is " val } $ $ gawk -f tst.awk foo value is 23
In other awk you will need to use [g] sub () and / or match () and / or substr () depending on what else you do / don't want to match. For instance:
$ cat tst.awk BEGIN { str = "foo=23" val = substr(str,match(str,/foo=[0-9]+/)+length("foo=")) print "foo value is " val } $ awk -f tst.awk foo value is 23
You will need the third arg of ', RLENGTH-length ("foo =")' on the substr () call if the target pattern is not at the end of the line. Make the "foo =" variable if you want, and if it itself can contain RE, it will take a few more steps.
source share