Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#1
Post
by darioit » 16 Sep 2020 04:16
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
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 16 Sep 2020 06:37
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
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#3
Post
by darioit » 16 Sep 2020 22:37
Thank you Steffen, always the best!
I try only 1 caret before parentesis, but not before equal