python - Using RegEx to match patterns in parameters -


I want to give an IP address as a python script as a parameter and to view the IP address format I would like to use regex for supply, but I'm getting an error while trying to run the script.

The script looks like this: import import rgip import script, ip_address, client_name, printer_model, hostname, mac_ address = argv ip_check = re.compile ("^ (10) \. (0) \ [0- 9]? [0- 9]? [0- 9] [[0-9]? [0-9]? [0-9] $ ") if Ip_check.match (ip_address) and "invalid ip address" endiff

every time I try to run the script, I get:

  If ip_check.match (ip_address) ^ syntax error: invalid syntax   

What's going on? Do I need to convert ip_address to raw data before being analyzed using RegEx? Import import rg script, ip_address, client_name, printer_model, hostname, mac_ address = argv import import from

  import Ip_check = re.compile (r "^ (10) \. (0) \. [0-9]? [0-9] [0-9] \. [0- 9]? [0- 9]? [ 0-9] $ ") if ip_check.match (ip_address): continue: return" invalid IP address "  

Try it out. Use the r mode to create a pattern and use : to if and and .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -