0

I have this batch script:

setlocal enableDelayedExpansion

set filename=%1%
set archive=%2%
set aleph=%3%
set bet=%4%
set gimel=%5%



if not x%filename:FEDBKA=%==x%filename% (

findstr /R <SHEM-HAKOVETZ>.*?(?:aa|tt|cc|bb|dd).*?<\/SHEM-HAKOVETZ> %1%
if !errorlevel! == 0 (
    copy %filename% %archive%
    move %filename% %gimel%
    exit
)
findstr /R <SHEM-HAKOVETZ>.*?(?:rr|yy).*?<\/SHEM-HAKOVETZ> %1%
if !errorlevel! == 0 (
    copy %filename% %archive%
    move %filename% %aleph%
    exit
)
findstr /R <SHEM-HAKOVETZ>.*?(?:ww|oo|pp).*?<\/SHEM-HAKOVETZ> %1%
if !errorlevel! == 0 (
    copy %filename% %archive%
    move %filename% %bet%
    exit
)
exit
)

when I run the script, I get:

.*? was unexpected at this time.

Im looking for a xml tag pattern such as:

<SHEM-HAKOVETZ>104000514813450ttS000005201811221405351025.DAT</SHEM-HAKOVETZ>

where "tt" can be switched with the other options in the regex

If I replace the regex with simple findstr expression:

findstr "aa tt cc bb dd" %1%

everything works well, but it doesn't meet my exact demand.

Compo
  • 36,585
  • 5
  • 27
  • 39
livnt
  • 45
  • 5
  • 2
    ok, firstly, what is `%1%` `%2%` etc ? do you mean `%1` `%2` ? – Gerhard Mar 13 '19 at 08:58
  • I guess so.. it's working well though – livnt Mar 13 '19 at 09:05
  • 2
    Always put the search expressions of [`findstr`](http://ss64.com/nt/findstr.html) in between quotation marks `""` (check out the examples when typing `findstr /?` into CMD); your strings contain several characters that have got special meanings (e. g., [`<`, `>`, `|`](http://ss64.com/nt/syntax-redirection.html), [`(`, `)`](http://ss64.com/nt/syntax-brackets.html)). And the command line agruments are accessed by `%1`, `%2`, etc., but not by `%1%`, `2%`; the latter might work in your situation, but only by coincidence since there is no `%`-sign following; if there would, things would go wrong... – aschipfl Mar 13 '19 at 09:13
  • I tried the quotation marks, with no success. If i look at examples on the net, i see no quotations marks – livnt Mar 13 '19 at 09:20
  • 1
    @livnt, I would love to see the websites that are showing you not to use quotes around the search strings. It is not a best practice at all. Telling us you are not having any success doesn't help us help you solve the problem. You need to provide any current error messages you are receiving. I would also find it hard to believe that ANY website site said using `%1%` is okay. – Squashman Mar 13 '19 at 13:57

1 Answers1

0

Your findstr regex is not working because as far as I know, there is no | as an OR operator.

But you can try it like this:

findstr /R /C:"<SHEM-HAKOVETZ>.*aa.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*tt.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*bb.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*cc.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*dd.*<\/SHEM-HAKOVETZ>" %FILENAME%


findstr /R /C:"<SHEM-HAKOVETZ>.*rr.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*yy.*<\/SHEM-HAKOVETZ>" %FILENAME%


findstr /R /C:"<SHEM-HAKOVETZ>.*ww.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*oo.*<\/SHEM-HAKOVETZ>" ^
    /C:"<SHEM-HAKOVETZ>.*pp.*<\/SHEM-HAKOVETZ>" %FILENAME%
devopsfun
  • 1,368
  • 2
  • 15
  • 37