我有一個基于 REGEXMATCH 的公式
=ArrayFormula(if( REGEXMATCH(topProdukte!AV2,"^si|si\d |si-"), topProdukte!AV2, "NO"))
現在我嘗試添加一個 AND NOT 條件并在某些事情上失敗。我用負面的前瞻來嘗試
=ArrayFormula(if( REGEXMATCH(topProdukte!AV2,"^(?!sia)si|si\d |si-"), topProdukte!AV2, "NO"))按照https://stackoverflow.com/a/3194881/1992004中的建議- 但收到錯誤 #REF,不是有效的正則運算式。
最后,我需要匹配包含^si|si\d |si-但不包含*sia*.
uj5u.com熱心網友回復:
你需要做兩件事:
- 確保您的所有正則運算式匹配整個字串,因為它是來自
REGEXMATCH - 添加一個單獨的陳述句,檢查
sia字串中是否不存在。
所以,一個可能的解決方案是
=ArrayFormula(if( AND(NOT(REGEXMATCH(topProdukte!AV2, ".*sia.*")), REGEXMATCH(topProdukte!AV2,"^si.*|.*si\d.*|.*si-.*")), topProdukte!AV2, "NO"))
這里,
AND(...,...)需要兩個條件都通過/回傳真NOT(REGEXMATCH(topProdukte!AV2, ".*sia.*"))- 確保字串確實NOT包含sia(注意.*兩端確保整個字串都被消耗)REGEXMATCH(topProdukte!AV2,"^si.*|.*si\d.*|.*si-.*")- 您已經擁有的部分:它匹配si字串的開頭、sidigit 或si-字串中的任何位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/341572.html
