问题
Using Google re2 https://github.com/google/re2/blob/master/doc/syntax.txt
From a couple of lines like
- I love Rock
- I love Rock and scissors
- I hate paper
- I like Rock, paper and scissors
- I'd love myself
I want to extract "Rock", "paper"and "scissors" from each line. I want the regex to match all the above five lines and give me Rock, paper and scissors where it found something. I'm predominantly using this in Google sheets, but any Google re2 regex should help.
I've tried....
".*(([Rock]{0,4})).*"
".*(([Rock]{4})|([Rock]{0})).*"
=REGEXEXTRACT(A2,".*(Rock{0,2}).*(paper{0,2}).*(scissors{0,2}).*")
and multiple other combinations to get Rock from any line, if present... But, it always prefers zero rather than four... Even If it finds Rock , it returns empty strings. If i replace {0} with {1} i get "k" even though the full Rock is found.
Any ideas?
回答1:
I found some regex features are not supported in Google Sheets so far.
Please, try this workaround:
=ArrayFormula(IFERROR(REGEXREPLACE(A3,REGEXREPLACE(A3,"(Rock|paper|scissors)","(.*)"),{"$1","$2","$3"})))
In step 1 this formula makes regex for step2:
回答2:
[Rock]
will search for letters R o c k. Instead, use (Rock)
来源:https://stackoverflow.com/questions/45456630/extract-multiple-values-if-present-from-cell-in-google-spreadsheets