Reputation: 3768
Really simple, but I can get the 'greediness' of regex to work like I want. Say you have:
unlist(stringr::str_extract_all("XXXXSXTXXX","([A-Z]{2}[T|S][A-Z]{2})"))
This gives only the first match:
[1] "XXSXT"
How can I change the regex behaviour to give me both matches with S and T (without use two separate patterns), like:
[1] "SXTXX" "XXSXT"
Upvotes: 1
Views: 270
Reputation: 67968
You need to use lookahead
for that with perl=True
option for match in R.
(?=([A-Z]{2}[TS][A-Z]{2}))
See demo.
https://regex101.com/r/cJ6zQ3/23
Upvotes: 1