I am a newbie in Windows batch scripting. I have a question though.
In Windows batch scripting, 开发者_开发百科how will I know if a variable is a valid URL or not?
Example:
Valid URL:
url=https://stackoverflow.com/questions/ask
Invalid URL:
url=not a valid url
You might use FINDSTR to validate your URL by matching it against a regular expression. See the answers to this Stack Overflow question Regular expressions in findstr
Basically you'll have to understand
- how to use FINDSTR and its /R switch. See - HELP FINDSTR
- how to code a regex for matching and validating URLs. Google for regex tutorial. - Hint: - (http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
- and how to interpret FINDSTR results in a batch file. See - HELP FOR
This is simple and should work in most cases:
setlocal enableextensions enabledelayedexpansion
set URL=url to test
if not x%URL:http://=%==x%URL% goto http
if not x%URL:https://=%==x%URL% goto http
if not x%URL:ftp://=%==x%URL% goto ftp
REM else
echo invalid url!
Don't bother. Whatever you use won't be identical to whatever rules the program you're about to run uses. Just let the program decide.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论