我正在尝试获取一系列令牌,例如"((token 1))"
, "((token 2))"
。我有以下代码:
sentence = "I had a ((an adjective)) sandwich for breakfast today. It oozed all over my ((a body part)) and ((a noun))."
token_arr = sentence.scan(/\(\(.*\)\)/)
# => ["((an adjective))", "((a body part)) and ((a noun))"]
"))"
上面的代码在句子中第一次出现 of 时不会停止匹配"It oozed..."
。我想我需要一个负前瞻运算符,但我不确定这是否是正确的方法。