我需要比较字符串以满足某些条件。条件不一定是我可以使用正则表达式而是“表达式”条件匹配的模式。
例如,当数字介于2个值之间时,我想匹配一个字符串:
inputString = "The price of a flight to Paris is 550$ and tomorrow will go up by 150$"
matchingCondition = "The price of a flight to Paris is EXPRESSION( 500 < X < 600)$ and tomorrow will go up by EXPRESSION(100 < Y < 200)$"
我需要在随机文本上运行这种比较,这些随机文本看起来不像输入字符串。
即。
inputString = "blah blah blah"
我希望能够使用简单的true / false函数进行比较。即:
match(inputString,matchingCondition) -> Boolean
示例:
match(inputString : "The price of the flight is 400$",matchingCondition : "The price of the flight is EXPRESSION( 300$ < X < 401)$") -> true
match(inputString : "The price of the flight is 402$",matchingCondition : "The price of the flight is EXPRESSION( 300$ < X < 401)$") -> false
match(inputString : "Blah blah blah",matchingCondition : "The price of the flight is EXPRESSION( 300$ < X < 401)$") -> false
有没有办法完成这种比较(例如使用NSPredicate
)