1

I want to extract the mobile phones from candidates' CVs.

The mobile phone format I want to extract is 69xxxxxxxx.

The mobile phone formats i come across in the CVs are:

69 xxx xxxxx
0030 69xxxxxxxx
+3069xxxxxxxx
69/xxxx/xxxx

The following formula works great but it extracts the first 10 digits detected and not the one that starts with 69.

=IFERROR(REGEXEXTRACT(TO_TEXT(SPLIT(REGEXREPLACE(I252;"\(|\)|\-| "; ""); CHAR(10))); "\d{10}"))
player0
  • 124,011
  • 12
  • 67
  • 124
thanasix
  • 37
  • 1
  • 6

3 Answers3

2

You may use

=IFERROR(REGEXEXTRACT(TO_TEXT(SPLIT(REGEXREPLACE(I252;"[-/() ]+"; ""); CHAR(10))); "(?:\+|00)?(?:30)?(69\d{8})"))

See the regex demo and the Google Sheets screenshot below:

enter image description here

The regex matches

  • (?:\+|00)? - an optional + or 00
  • (?:30)? - an optional 30
  • ( - start of the capturing group (only this value will be returned):
    • 69 - 69 value
    • \d{8} - eight digits
  • ) - end of the group.

You might consider appending \b at the end of the regex to avoid matching the 8 digits in chunks of more than 8 digits.

Note that the separator cleaning regex is [-/() ]+ now, it matches 1 or more -, /, (, ) and spaces.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

The solution to your problem is to make use of a regex lookbehind (although I do not know if Google Sheets supports this).

A regex lookbehind matches a pattern, but without including in the result. The syntax for this, with your example, is:

(?<=69)\d{10}

The picture below is taken from https://regex101.com/ (which is a super-useful tool when working with regexps).

enter image description here

Regex lookahead, lookbehind and atomic groups has some more examples of how lookaheads and lookbehinds work.

0

all you need is:

=ARRAYFORMULA(IFNA(REGEXREPLACE(REGEXEXTRACT(A1:A&""; "69.*"); "\s|/|\D+"; )))

0


or better:

=ARRAYFORMULA(IFNA(REGEXEXTRACT(REGEXREPLACE(A1:A&""; "\D+"; ); "69.{8}")))

0

player0
  • 124,011
  • 12
  • 67
  • 124
  • it works but it also extracts everything after the mobile number – thanasix Oct 29 '19 at 10:07
  • very nice! the only problem i found in CVs that have an irrelevant 69 before the mobile: eg. Name:XXX, Surname:YYY Address: Street name 69, Mobile: 6944xxxxxx. The output of the Regextract is: 696944xxxx – thanasix Oct 29 '19 at 16:16