'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))"
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, ...
COLUMNS are only A-Z
CELLS are [A-Z][1-*]
And replace only them & NOT replace any formula letter (i.e: SUM, AVERAGE, ...).
Solution 1:[1]
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[A-Z]+[0-9]*\b(?!\(), since a formula will always be the letters followed by an open parenthesis.
Or, if you're positive there aren't more than 26 columns, then you could shorten it even more with \b[A-Z][0-9]*\b(?!\(). That is, removing the quantifier for the letter.
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shenk |
