user7935276
user7935276

Reputation: 239

Find a partial string in a cell and return exact value using a formula?

I need some help on this. I would like to find two different partial strings in a cell using a formula. For example - if cell (A1) contains "Staples A-12345 Georgia, USA" or other cell may contain only "g345" or "g100, g000" or other times it contains both A-12345 g345 in a cell as an example.

My goal is to return a value of "GXXX" or if not present, use the "A-XXXXX".

Search A1 cell for partial text of "A-" or "G". (The "A-, must contain 7 characters" and "G, must contain 4 characters.)

I am currently using this formula. I am unable to display the actual string.

=IFS(
ISNUMBER(SEARCH("*A-*",A1)),"TRUE",
ISNUMBER(SEARCH("*G*",A1)),"TRUE")

I got confused and stuck on this.Your time and help is greatly appreciated. Thank you.

Upvotes: 1

Views: 803

Answers (1)

player0
player0

Reputation: 1

use:

=IFNA(IF(A1="",,
 IF(REGEXMATCH(A1, "(g\d{3}).*(g\d{3})|(g\d{3})"), TEXTJOIN(", ", 1, 
  REGEXEXTRACT(A1, "(g\d{3}).*(g\d{3})|(g\d{3})")), REGEXEXTRACT(A1, "A-\d{5}"))), A1)

0

Upvotes: 2

Related Questions