Search code examples
arraysregexgoogle-sheetsgoogle-sheets-formulaextract

Trying to display first two numerical numbers


I am trying to parse this so the numbers before "-" are displayed only. Sometimes it will be a single digit and sometimes double.

I tried =LEFT(B4,FIND("-",B4)-1)

And it shoots an error. image of error


Solution

  • try:

    =REGEXEXTRACT(TO_TEXT(B4); "(\d+)")*1
    

    for array:

    =INDEX(IFERROR(REGEXEXTRACT(TO_TEXT(B4:B); "(\d+)")*1))
    

    update:

    =INDEX(IFERROR(REGEXEXTRACT(TO_TEXT(C1:C), "^(\d+)")*1))
    

    enter image description here