如何重用子字符串进行匹配?

时间:2018-07-02 21:17:31

标签: r regex

我正在尝试匹配一串字符串中的机场城市对:

raw_city_pairs <- "EWR/MIA
MIA/JFK
FLR/BRU/EVN
FCO/JFK_BOS/FCO"
city_pair <- "[A-Z]{3}/[A-Z]{3}"
regmatches(raw_city_pairs, gregexpr(city_pair, raw_city_pairs), invert=F)

该功能接近正常运行,但是我希望它在第3行中重用“ BRU”并成对返回“ BRU / EVN”。我该怎么做?

0 个答案:

没有答案