0

我需要比较字符串以满足某些条件。这些条件不一定是我可以使用正则表达式匹配的模式,而是“表达式”条件。

例如,当数字介于 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)$"

我需要对不一定看起来像有问题的输入字符串的随机文本进行比较。

IE

inputString = "blah blah blah"

我希望能够使用简单的真/假函数进行比较。IE:

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例如使用)

4

0 回答 0