diff --git a/src/helpers/numbers.ts b/src/helpers/numbers.ts index 0b3a677bab..43061a1933 100644 --- a/src/helpers/numbers.ts +++ b/src/helpers/numbers.ts @@ -8,7 +8,7 @@ * formula, commas are used to separate arguments * - it does not support % symbol, in formulas % is an operator */ -export const formulaNumberRegexp = /^-?\d+(\.?\d*(e\d+)?)?|^-?\.\d+/; +export const formulaNumberRegexp = /(^-?\d+(\.?\d*(e\d+)?)?|^-?\.\d+)(?!\w|!)/; const pIntegerAndDecimals = "(\\d+(,\\d{3,})*(\\.\\d*)?)"; // pattern that match integer number with or without decimal digits const pOnlyDecimals = "(\\.\\d+)"; // pattern that match only expression with decimal digits diff --git a/tests/formulas/tokenizer.test.ts b/tests/formulas/tokenizer.test.ts index 05c4240c75..45ac00b81e 100644 --- a/tests/formulas/tokenizer.test.ts +++ b/tests/formulas/tokenizer.test.ts @@ -208,6 +208,22 @@ describe("tokenizer", () => { { type: "OPERATOR", value: "=" }, { type: "REFERENCE", value: "'a '' b'!A1" }, ]); + expect(tokenize("=1name!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "1name!A1" }, + ]); + expect(tokenize("=123!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "123!A1" }, + ]); + expect(tokenize("='1name'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "'1name'!A1" }, + ]); + expect(tokenize("='123'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "'123'!A1" }, + ]); }); test("wrong references", () => {