You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Sheets中实现指定字符组合替换为符号的技术问询

Solution for Pair-Based Replacement in Google Sheets RPG Tracker

Core Approach

To replace specific character pairs only when both exist, combine conditional checks with regex replacement. Here's how to implement it:

Formula Implementation

Use LET to simplify repetitive code and add conditional logic:

=LET(
  original, JOIN("",ARRAYFORMULA(IF(INDEX(Tracker!C:AB,MATCH(A2,Tracker!A:A,0),Tracker!C:AB),Tracker!C1:AB1,))),
  IF(
    AND(REGEXMATCH(original, "A"), REGEXMATCH(original, "T")),
    REGEXREPLACE(original, "[AT]", "#"),
    original
  )
)

Breakdown of the Formula

  • LET(original, ...): Stores your original extracted letter string in a temporary variable to avoid repeating the full extraction formula.
  • AND(REGEXMATCH(original, "A"), REGEXMATCH(original, "T")): Checks if both target characters (A and T) are present in the string.
  • REGEXREPLACE(original, "[AT]", "#"): Replaces every occurrence of A or T with # only if both characters exist.
  • Fallback: If either character is missing, returns the original unmodified string.

Handling Multiple Pairs

If you need to handle additional character pairs (e.g., B and S replaced with @), extend the formula with nested IF statements inside LET:

=LET(
  original, JOIN("",ARRAYFORMULA(IF(INDEX(Tracker!C:AB,MATCH(A2,Tracker!A:A,0),Tracker!C:AB),Tracker!C1:AB1,))),
  step1, IF(AND(REGEXMATCH(original, "A"), REGEXMATCH(original, "T")), REGEXREPLACE(original, "[AT]", "#"), original),
  step2, IF(AND(REGEXMATCH(step1, "B"), REGEXMATCH(step1, "S")), REGEXREPLACE(step1, "[BS]", "@"), step1),
  step2
)

Notes

  • Replace "A", "T", and "#" with your actual target characters and replacement symbol as needed.
  • The [AT] in the regex pattern matches any single occurrence of A or T; adjust this to match your pair characters.

内容的提问来源于stack exchange,提问作者Browndog

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 17:55:22