You are not logged in.
Hi I am trying to use FindStr's reg expressions and think I have it a limitation.
SETLOCAL enabledelayedexpansion
SET SuffixLine=//test.test#1 edit
Echo !SuffixLine! | FINDSTR /RI "^.*#[0-9]* \<edit\>"
ENDLOCAL
To my mind this appears to search for;
Start of line
anything until #
then any amount of numbers until a space then 'edit'
In actual fact the space divides the terms in to two so finds lines with either # OR edit in them. I need AND (and in that order).
Trying to use [ ] instead of the space did not work with. I can't use literal search as there is a variable number (of numbers) after the # (and they're might've be a # in the path earlier)
How should I do this?
Offline
You must include the /C parameter to insert a space in the reg exp. Although the documentation indicate that /C "perform a literal search", that is not true. /C allows to include spaces; the search is literal if no or /L switch is given, and reg exp if /R switch is given.
Antonio
Last edited by Aacini (27 Jan 2016 17:43)
Offline
Hi Aacini,
Thanks for your pointer. I had to:
- User /C:"teststring" syntax as when I just added C to the the above switches it would report '/C ignored'
- I had to the remove the \< and \> around my word 'edit'. Not sure why this was necessary but perhaps it's incorrect regex or perhaps it's a findstr bug? (It did previously 'work' when just searching for edit as a single term).
Any way this now works 'correctly' (and removing the /C: makes it break again):
@ECHO ON
SETLOCAL enabledelayedexpansion
SET SuffixLine=//test.test#1 edit
SET noHASH=//test.test1 edit
SET noEdit=//test.test#1 add
:: Using redirection as suggested by dbenham http://stackoverflow.com/questions/10629139/piped-variable-into-findstr-w-regular-expressions-and-escaped-double-quotes
:: BOTH A #some numbers, a space and then edit
Echo !SuffixLine! | FINDSTR /RI /C:"^.*#[0-9]*[ ]edit"
ECHO Error level is %ERRORLEVEL%
::to confirm it's using AND logic
Echo !noHASH! | FINDSTR /RI /C:"^.*#[0-9]*[ ]edit"
ECHO Error level is %ERRORLEVEL%
Echo !noEdit! | FINDSTR /RI /C:"^.*#[0-9]*[ ]edit"
ECHO Error level is %ERRORLEVEL%
ENDLOCAL
pause
Last edited by moconnell (28 Jan 2016 11:54)
Offline