How can I do a negative regex match in batch?












1















This time, I am unable to create an if statement for my previous post



I'm trying to check if the value is in this form: ^dd.d$



Most of the time, it will. However, it is sometimes unavailable.



In other scripting languages, I can manage it, but I cannot, for some unknown reasons, figure out how to do it in batch.



So, it should be something like:



if not findstr /R "^dd.d$" %newvalue%
set newvalue=


If it's not "^dd.d$", then set newvalue blank. This is only to blank newvalue when it is not found because it will give random results.



Can somebody help me out? What's the best way to do this if statement?



Thanks in advance.










share|improve this question

























  • @npocmaka: I got this error message: FINDSTR: Cannot open 12.0

    – Ricky
    Dec 31 '18 at 15:04






  • 1





    FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

    – Compo
    Dec 31 '18 at 15:06













  • @Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

    – Ricky
    Dec 31 '18 at 15:12








  • 1





    @Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

    – Compo
    Dec 31 '18 at 15:30








  • 4





    With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

    – LotPings
    Dec 31 '18 at 15:49


















1















This time, I am unable to create an if statement for my previous post



I'm trying to check if the value is in this form: ^dd.d$



Most of the time, it will. However, it is sometimes unavailable.



In other scripting languages, I can manage it, but I cannot, for some unknown reasons, figure out how to do it in batch.



So, it should be something like:



if not findstr /R "^dd.d$" %newvalue%
set newvalue=


If it's not "^dd.d$", then set newvalue blank. This is only to blank newvalue when it is not found because it will give random results.



Can somebody help me out? What's the best way to do this if statement?



Thanks in advance.










share|improve this question

























  • @npocmaka: I got this error message: FINDSTR: Cannot open 12.0

    – Ricky
    Dec 31 '18 at 15:04






  • 1





    FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

    – Compo
    Dec 31 '18 at 15:06













  • @Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

    – Ricky
    Dec 31 '18 at 15:12








  • 1





    @Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

    – Compo
    Dec 31 '18 at 15:30








  • 4





    With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

    – LotPings
    Dec 31 '18 at 15:49
















1












1








1


1






This time, I am unable to create an if statement for my previous post



I'm trying to check if the value is in this form: ^dd.d$



Most of the time, it will. However, it is sometimes unavailable.



In other scripting languages, I can manage it, but I cannot, for some unknown reasons, figure out how to do it in batch.



So, it should be something like:



if not findstr /R "^dd.d$" %newvalue%
set newvalue=


If it's not "^dd.d$", then set newvalue blank. This is only to blank newvalue when it is not found because it will give random results.



Can somebody help me out? What's the best way to do this if statement?



Thanks in advance.










share|improve this question
















This time, I am unable to create an if statement for my previous post



I'm trying to check if the value is in this form: ^dd.d$



Most of the time, it will. However, it is sometimes unavailable.



In other scripting languages, I can manage it, but I cannot, for some unknown reasons, figure out how to do it in batch.



So, it should be something like:



if not findstr /R "^dd.d$" %newvalue%
set newvalue=


If it's not "^dd.d$", then set newvalue blank. This is only to blank newvalue when it is not found because it will give random results.



Can somebody help me out? What's the best way to do this if statement?



Thanks in advance.







regex batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 14:53









briantist

31.7k34275




31.7k34275










asked Dec 31 '18 at 14:46









RickyRicky

245




245













  • @npocmaka: I got this error message: FINDSTR: Cannot open 12.0

    – Ricky
    Dec 31 '18 at 15:04






  • 1





    FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

    – Compo
    Dec 31 '18 at 15:06













  • @Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

    – Ricky
    Dec 31 '18 at 15:12








  • 1





    @Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

    – Compo
    Dec 31 '18 at 15:30








  • 4





    With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

    – LotPings
    Dec 31 '18 at 15:49





















  • @npocmaka: I got this error message: FINDSTR: Cannot open 12.0

    – Ricky
    Dec 31 '18 at 15:04






  • 1





    FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

    – Compo
    Dec 31 '18 at 15:06













  • @Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

    – Ricky
    Dec 31 '18 at 15:12








  • 1





    @Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

    – Compo
    Dec 31 '18 at 15:30








  • 4





    With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

    – LotPings
    Dec 31 '18 at 15:49



















@npocmaka: I got this error message: FINDSTR: Cannot open 12.0

– Ricky
Dec 31 '18 at 15:04





@npocmaka: I got this error message: FINDSTR: Cannot open 12.0

– Ricky
Dec 31 '18 at 15:04




1




1





FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

– Compo
Dec 31 '18 at 15:06







FindStr does not use standard regex, for digits it uses [0-9] and as . is a wildcard metacharacter, a literal . requires escaping with the character. Please open a Command Prompt window and enter FindStr /? to read the usage information. Also, please note that FindStr will return the entire line, not just a specific string within that line.

– Compo
Dec 31 '18 at 15:06















@Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

– Ricky
Dec 31 '18 at 15:12







@Compo: I did, but I can't figure out how to implement an if statement while using FindStr. "^[0-9][0-9].[0-9]$" still gives me the same error message.

– Ricky
Dec 31 '18 at 15:12






1




1





@Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

– Compo
Dec 31 '18 at 15:30







@Ricky, that's of absolutely no use to us, as we cannot see the command or string your running the FindStr command against. Please edit your question, to include your code as it now stands. Please make sure before you do that, that your code follows the syntax as shown under the output from the usage information.

– Compo
Dec 31 '18 at 15:30






4




4





With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

– LotPings
Dec 31 '18 at 15:49







With your syntax above findstr expects %newvalue% to be file, not a string. You'll have to use echo: Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)

– LotPings
Dec 31 '18 at 15:49














1 Answer
1






active

oldest

votes


















1














The very good working solution posted by LotPings is:



Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)


I suggest a little bit different single line solution:



echo:%newvalue%|%SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul && (echo matched pattern) || (echo didn't match pattern)


Or easier readable and working for really any string value assigned to environment variable newvalue:



setlocal EnableExtensions EnableDelayedExpansion
echo:!newvalue!| %SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul
if errorlevel 1 (
echo Value does not match the regular expression pattern.
) else (
echo Value matches the regular expression pattern.
)
endlocal


A colon is used between command echo and the string assigned to environment variable newvalue instead of a space to avoid that command ECHO outputs the current status of command echoing in case of newvalue is not defined at all.



The last solution uses delayed expansion to avoid that the command line with ECHO and FINDSTR does not work or does something completely different than it is written for if the string assigned to variable newvalue contains operators like &<>|.



It is important that there is no space left to redirection operator | which pipes output of command ECHO to the command FINDSTR as input because of this space character would be also output by command ECHO and the regular expression find would never be positive. A space right to | does not matter as last example demonstrates.



FINDSTR does not support d as representation for any digit. It is necessary to specify the characters to match in a self-defined character class in square brackets. FINDSTR matches with [0-9] the characters 0123456789¹²³. It is necessary to use [0123456789] to match just the characters 0123456789 without ¹²³.



. means any character, except the dot is escaped with a backslash in which case it is interpreted as literal character.



A search string in "..." is interpreted by FINDSTR by default as regular expression string. But I think, it is always good to make use of /L or /R to make it 100% clear for FINDSTR and for every reader how the search string should be interpreted, as literal or as regular expression string.



FINDSTR exits with value 1 on no positive match on searched input character stream and 0 on at least one positive match. The exit code of FINDSTR can be evaluated as shown above and described in detail in single line with multiple commands using Windows batch file.



The output of FINDSTR on a positive match is of no interest and therefore redirected to device NUL to suppress it.



For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




  • echo /?

  • endlocal /?

  • findstr /?

  • if /?

  • setlocal /?


See also the Microsoft article about Using command redirection operators and DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ for the reason why using : after echo is often better than a space on output of a string read from a file or entered by a user.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988684%2fhow-can-i-do-a-negative-regex-match-in-batch%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The very good working solution posted by LotPings is:



    Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)


    I suggest a little bit different single line solution:



    echo:%newvalue%|%SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul && (echo matched pattern) || (echo didn't match pattern)


    Or easier readable and working for really any string value assigned to environment variable newvalue:



    setlocal EnableExtensions EnableDelayedExpansion
    echo:!newvalue!| %SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul
    if errorlevel 1 (
    echo Value does not match the regular expression pattern.
    ) else (
    echo Value matches the regular expression pattern.
    )
    endlocal


    A colon is used between command echo and the string assigned to environment variable newvalue instead of a space to avoid that command ECHO outputs the current status of command echoing in case of newvalue is not defined at all.



    The last solution uses delayed expansion to avoid that the command line with ECHO and FINDSTR does not work or does something completely different than it is written for if the string assigned to variable newvalue contains operators like &<>|.



    It is important that there is no space left to redirection operator | which pipes output of command ECHO to the command FINDSTR as input because of this space character would be also output by command ECHO and the regular expression find would never be positive. A space right to | does not matter as last example demonstrates.



    FINDSTR does not support d as representation for any digit. It is necessary to specify the characters to match in a self-defined character class in square brackets. FINDSTR matches with [0-9] the characters 0123456789¹²³. It is necessary to use [0123456789] to match just the characters 0123456789 without ¹²³.



    . means any character, except the dot is escaped with a backslash in which case it is interpreted as literal character.



    A search string in "..." is interpreted by FINDSTR by default as regular expression string. But I think, it is always good to make use of /L or /R to make it 100% clear for FINDSTR and for every reader how the search string should be interpreted, as literal or as regular expression string.



    FINDSTR exits with value 1 on no positive match on searched input character stream and 0 on at least one positive match. The exit code of FINDSTR can be evaluated as shown above and described in detail in single line with multiple commands using Windows batch file.



    The output of FINDSTR on a positive match is of no interest and therefore redirected to device NUL to suppress it.



    For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




    • echo /?

    • endlocal /?

    • findstr /?

    • if /?

    • setlocal /?


    See also the Microsoft article about Using command redirection operators and DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ for the reason why using : after echo is often better than a space on output of a string read from a file or entered by a user.






    share|improve this answer




























      1














      The very good working solution posted by LotPings is:



      Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)


      I suggest a little bit different single line solution:



      echo:%newvalue%|%SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul && (echo matched pattern) || (echo didn't match pattern)


      Or easier readable and working for really any string value assigned to environment variable newvalue:



      setlocal EnableExtensions EnableDelayedExpansion
      echo:!newvalue!| %SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul
      if errorlevel 1 (
      echo Value does not match the regular expression pattern.
      ) else (
      echo Value matches the regular expression pattern.
      )
      endlocal


      A colon is used between command echo and the string assigned to environment variable newvalue instead of a space to avoid that command ECHO outputs the current status of command echoing in case of newvalue is not defined at all.



      The last solution uses delayed expansion to avoid that the command line with ECHO and FINDSTR does not work or does something completely different than it is written for if the string assigned to variable newvalue contains operators like &<>|.



      It is important that there is no space left to redirection operator | which pipes output of command ECHO to the command FINDSTR as input because of this space character would be also output by command ECHO and the regular expression find would never be positive. A space right to | does not matter as last example demonstrates.



      FINDSTR does not support d as representation for any digit. It is necessary to specify the characters to match in a self-defined character class in square brackets. FINDSTR matches with [0-9] the characters 0123456789¹²³. It is necessary to use [0123456789] to match just the characters 0123456789 without ¹²³.



      . means any character, except the dot is escaped with a backslash in which case it is interpreted as literal character.



      A search string in "..." is interpreted by FINDSTR by default as regular expression string. But I think, it is always good to make use of /L or /R to make it 100% clear for FINDSTR and for every reader how the search string should be interpreted, as literal or as regular expression string.



      FINDSTR exits with value 1 on no positive match on searched input character stream and 0 on at least one positive match. The exit code of FINDSTR can be evaluated as shown above and described in detail in single line with multiple commands using Windows batch file.



      The output of FINDSTR on a positive match is of no interest and therefore redirected to device NUL to suppress it.



      For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




      • echo /?

      • endlocal /?

      • findstr /?

      • if /?

      • setlocal /?


      See also the Microsoft article about Using command redirection operators and DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ for the reason why using : after echo is often better than a space on output of a string read from a file or entered by a user.






      share|improve this answer


























        1












        1








        1







        The very good working solution posted by LotPings is:



        Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)


        I suggest a little bit different single line solution:



        echo:%newvalue%|%SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul && (echo matched pattern) || (echo didn't match pattern)


        Or easier readable and working for really any string value assigned to environment variable newvalue:



        setlocal EnableExtensions EnableDelayedExpansion
        echo:!newvalue!| %SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul
        if errorlevel 1 (
        echo Value does not match the regular expression pattern.
        ) else (
        echo Value matches the regular expression pattern.
        )
        endlocal


        A colon is used between command echo and the string assigned to environment variable newvalue instead of a space to avoid that command ECHO outputs the current status of command echoing in case of newvalue is not defined at all.



        The last solution uses delayed expansion to avoid that the command line with ECHO and FINDSTR does not work or does something completely different than it is written for if the string assigned to variable newvalue contains operators like &<>|.



        It is important that there is no space left to redirection operator | which pipes output of command ECHO to the command FINDSTR as input because of this space character would be also output by command ECHO and the regular expression find would never be positive. A space right to | does not matter as last example demonstrates.



        FINDSTR does not support d as representation for any digit. It is necessary to specify the characters to match in a self-defined character class in square brackets. FINDSTR matches with [0-9] the characters 0123456789¹²³. It is necessary to use [0123456789] to match just the characters 0123456789 without ¹²³.



        . means any character, except the dot is escaped with a backslash in which case it is interpreted as literal character.



        A search string in "..." is interpreted by FINDSTR by default as regular expression string. But I think, it is always good to make use of /L or /R to make it 100% clear for FINDSTR and for every reader how the search string should be interpreted, as literal or as regular expression string.



        FINDSTR exits with value 1 on no positive match on searched input character stream and 0 on at least one positive match. The exit code of FINDSTR can be evaluated as shown above and described in detail in single line with multiple commands using Windows batch file.



        The output of FINDSTR on a positive match is of no interest and therefore redirected to device NUL to suppress it.



        For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




        • echo /?

        • endlocal /?

        • findstr /?

        • if /?

        • setlocal /?


        See also the Microsoft article about Using command redirection operators and DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ for the reason why using : after echo is often better than a space on output of a string read from a file or entered by a user.






        share|improve this answer













        The very good working solution posted by LotPings is:



        Echo:%newvalue%|findstr "^[0-9][0-9].[0-9]$" >Nul 2>&1 &&(echo matched pattern)||(echo didn't match pattern)


        I suggest a little bit different single line solution:



        echo:%newvalue%|%SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul && (echo matched pattern) || (echo didn't match pattern)


        Or easier readable and working for really any string value assigned to environment variable newvalue:



        setlocal EnableExtensions EnableDelayedExpansion
        echo:!newvalue!| %SystemRoot%System32findstr.exe /R "^[0123456789][0123456789].[0123456789]$" >nul
        if errorlevel 1 (
        echo Value does not match the regular expression pattern.
        ) else (
        echo Value matches the regular expression pattern.
        )
        endlocal


        A colon is used between command echo and the string assigned to environment variable newvalue instead of a space to avoid that command ECHO outputs the current status of command echoing in case of newvalue is not defined at all.



        The last solution uses delayed expansion to avoid that the command line with ECHO and FINDSTR does not work or does something completely different than it is written for if the string assigned to variable newvalue contains operators like &<>|.



        It is important that there is no space left to redirection operator | which pipes output of command ECHO to the command FINDSTR as input because of this space character would be also output by command ECHO and the regular expression find would never be positive. A space right to | does not matter as last example demonstrates.



        FINDSTR does not support d as representation for any digit. It is necessary to specify the characters to match in a self-defined character class in square brackets. FINDSTR matches with [0-9] the characters 0123456789¹²³. It is necessary to use [0123456789] to match just the characters 0123456789 without ¹²³.



        . means any character, except the dot is escaped with a backslash in which case it is interpreted as literal character.



        A search string in "..." is interpreted by FINDSTR by default as regular expression string. But I think, it is always good to make use of /L or /R to make it 100% clear for FINDSTR and for every reader how the search string should be interpreted, as literal or as regular expression string.



        FINDSTR exits with value 1 on no positive match on searched input character stream and 0 on at least one positive match. The exit code of FINDSTR can be evaluated as shown above and described in detail in single line with multiple commands using Windows batch file.



        The output of FINDSTR on a positive match is of no interest and therefore redirected to device NUL to suppress it.



        For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




        • echo /?

        • endlocal /?

        • findstr /?

        • if /?

        • setlocal /?


        See also the Microsoft article about Using command redirection operators and DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ for the reason why using : after echo is often better than a space on output of a string read from a file or entered by a user.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 17:13









        MofiMofi

        28.4k83777




        28.4k83777
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988684%2fhow-can-i-do-a-negative-regex-match-in-batch%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'