Search code examples
arraysregexgoogle-sheetsextractre2

Regexextract number just before specific text Google sheets


I need to extract the number that comes right before the text Positions

Example String:

Medical Specialist (Anaestheologist) (4 Positions) at Ministry

Valid Output should be 4

Example String 2 (If text Positions doesn't exist)

Medical Specialist (Anaestheologist) (4) at Ministry

Valid Output

4

I tried:

=REGEXEXTRACT(A24,"\(.*Positions.*\)") but it did not work.


Solution

  • try:

    =ARRAYFORMULA(REGEXEXTRACT(A1:A2; "(\d+)(?: Positions)?"))
    

    enter image description here