Search code examples
regexgoogle-sheetsgoogle-sheets-formula

Regular Expressions: count the number of numeric characters between two specific characters in a string in google sheets


In google spreadsheets, using regular expressions, how can I count the characters, numeric only, that are between the first hyphen of a string (from left to right) and the first comma after the hyphen? The correct thing would be to count only the characters "2, 3, 4 and 5", that is, 4 characters.

enter image description here


Solution

  • You can use the regex "-.*?(\d*).*?," to get the number out with REGEXTRACT(A2, "-.*?(\d*).*?,") and then use LEN to get the length:

    =LEN(REGEXTRACT(A2, "-.*?(\d*).*?,"))