batch file - Findstr: Regex with Variable -


i have text file , formated this;

(1992){0103644}[00004] (1999){0137523}[00019] (1991){0103064}[00098] (2001){0246578}[00103] (2011){1399103}[00150] 

what trying finding variable (which entered user) inside text. variable had search between {} trying;

setlocal enabledelayedexpansion set "sira=1" set "test=103" /f "tokens=1-3 delims=(){}[]" %%a in ('findstr /irc:"\{[0-9]*!test![0-9]*\}" %murl%') (   set fisim[!sira!]=%%a   set fyil[!sira!]=%%b   set fidd[!sira!]=%%c   set /a sira+=1 ) set /a sira-=1 /l %%i in (1,1,!sira!) call :_yazdir "%%i" "!fisim[%%i]!" "!fyil[%%i]!" "!fidd[%%i]!" "!satirrengi!" goto :eof 

it works if write variable inside findstr (in case !test! replaced 103). there possible way find ?

ps: %murl% contains name of text file.

ps: :_yazdir function use print

if can tap regex engine supports lookarounds, can use regex:

(?<={)[^}]+(?=}) 

see demo

for instance, grep in perl mode, can do:

grep -p "(?<={)[^}]+(?=})" myfile 

in comments on windows, can use pcregrep (which part of pcre distribution).

explanation

  • the (?<={) lookbehind asserts precedes {
  • [^}]+ matches 1 or more chars not }
  • the (?=}) lookahead asserts follows }

reference


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -