I want to compare two strings in python ignoring some characters, like if the string is:
"http://localhost:13555/ChessBoard_x16_y20.bmp"
I want to ignore the values "16" and "20" in the string; no matter what these values are, if the rest of the string is same as this string is then I should get the result "TRUE". How can I do 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 it is for your case. A dot matches any symbol. A \d matches a digit. Some special symbols have to be escaped.
import re
if re.match(r'http://localhost:13555/ChessBoard_x\d\d_y\d\d\.bmp', URL):
print("TRUE")
else:
print("FALSE")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With