Page 1 of 1

Forfiles and escape char

Posted: 16 Sep 2020 04:16
by darioit
Hello,
this string works fine in dos shell

Code: Select all

curl --request POST "https://somesite/access_token" --user user:pass | grep -o -P -e "(?<=\"access_token\":\").+?(?=\")"
but If I try this:

Code: Select all

for /f %%a in ('curl --request POST "https://somesite/access_token" --user user:pass ^| grep -o -P -e "(?<=\"access_token\":\").+?(?=\")"') do set "TOKEN=%%a"
I got this error
.+?(? was unexpected at this time.

any idea? Thanks

Re: Forfiles and escape char

Posted: 16 Sep 2020 06:37
by aGerman
If I count the quotes then it seems that the closing parenthesis right before the point is neither escaped nor quoted. I suspect it is treated as to be closing the FOR clause. Try to escape it with a caret. Probably the equal sign, too.
Something like that for the regex pattern ...

Code: Select all

"(?<=\"access_token\":\"^).+?(?^=\")"
Steffen

Re: Forfiles and escape char

Posted: 16 Sep 2020 22:37
by darioit
Thank you Steffen, always the best!

I try only 1 caret before parentesis, but not before equal