Home > Software engineering >  Regular Expressions: count the number of numeric characters between two specific characters in a str
Regular Expressions: count the number of numeric characters between two specific characters in a str

Time:08-04

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

CodePudding user response:

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*).*?,"))

CodePudding user response:

Try this

=REGEXEXTRACT(REGEXEXTRACT(A2, "-. ?,"), "[0-9] ")

enter image description here

  • Related