[英]Regex (Javascript) - How to replace certain character in a given string
I have the following case:我有以下情况:
"SUM(A, SUM(A1, B, C), SUM(D, A3, F, M))" “总和(A,总和(A1,B,C),总和(D,A3,F,M))”
Is there I way I could identify all the cells/columns which are the following letters:我有什么办法可以识别所有具有以下字母的单元格/列:
Cells: A1, B1, C1, ... Columns: A, B, C, D, ...单元格:A1, B1, C1, ... 列:A, B, C, D, ...
COLUMNS are only AZ列只有 AZ
CELLS are [AZ][1-*]细胞是 [AZ][1-*]
And replace only them & NOT replace any formula letter (ie: SUM, AVERAGE, ...).并且只替换它们而不替换任何公式字母(即:SUM、AVERAGE、...)。
If I'm understanding correctly, the goal is basically to avoid ending up replacing the formula letters.如果我理解正确,目标基本上是避免最终替换公式字母。
Assuming you're able to use negative lookaheads, that could be done as simply as \b[AZ]+[0-9]*\b(?!\()
, since a formula will always be the letters followed by an open parenthesis.假设您能够使用负前瞻,这可以像
\b[AZ]+[0-9]*\b(?!\()
一样简单地完成,因为公式将始终是字母后跟一个开放插入语。
Or, if you're positive there aren't more than 26 columns, then you could shorten it even more with \b[AZ][0-9]*\b(?!\()
. That is, removing the quantifier for the letter.或者,如果您确定不超过 26 列,则可以使用
\b[AZ][0-9]*\b(?!\()
进一步缩短它。也就是说,删除量词对于这封信。
If there's some other constraint that would make this not work, then it would be helpful to have that information available in the question.如果还有其他一些限制会使它不起作用,那么在问题中提供该信息会很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.