我有一组字符串:
array = [ "nike air", "nike steam","nike softy" ,"nike strength",
"smooth sleeper","adidas air","addidas jogar","adidas softy","adidas heels"]
我想从中提取字符串作为类似sql的查询。
例如,如果用户输入单词“nike”。那么结果应该返回4个字符串
"nike air", "nike steam","nike softy" ,"nike strength"
例如,如果用户输入“阿迪达斯”。那么结果应该返回4个字符串
"adidas air","addidas jogar","adidas softy","adidas heels"
有可能吗?
最佳答案
array.grep(query)
返回与查询匹配的子集数组。