python - how to compare two strings ignoring few characters -
i want compare 2 strings in python ignoring characters, if string is:
"http://localhost:13555/chessboard_x16_y20.bmp"
i want ignore values "16"
, "20"
in string; no matter these values are, if rest of string same string should result "true"
. how can this?
example:
url = "http://localhost:13555/chessboard_x05_y12.bmp" if url == "http://localhost:13555/chessboard_x16_y16.bmp": print("true") else: print("false")
output:
true
use regular expressions. here case. dot matches symbol. \d matches digit. special symbols have escaped.
import re if re.match(r'http://localhost:13555/chessboard_x\d\d_y\d\d\.bmp', url): print("true") else: print("false")
Comments
Post a Comment