Using REGEX to Extract the text from the Data

Viewed 37

I have created below formula which works for some of the data not for the entire. I have been trying to extract those values which has ? at end where two cells are <>"".

Any help will be appreciatd.

=IF(OR(B2<>"",C2<>""),IFERROR(REGEXEXTRACT(A2,"^\*\*\*\ HEDAL - (.* )? ")),0)

enter image description here

Sheet Link

1 Answers

You can use

=IF(OR(B2<>"",C2<>""),IFERROR(REGEXEXTRACT(A2,"^\*\*\*\ HEDAL - (.*?\?) +- ")),"")

See the regex demo here. Details:

  • ^ - start of string
  • ***\ HEDAL - - *** HEDAL - text
  • (.*?\?) - Group 1: any zero or more chars other than line break chars, as few as possible, then a ? char (note you might need to change .*? to [^-]* to avoid matching the boundary - char)
  • +- - zero or more spaces, - and a space.

Demo screenshot:

enter image description here

Related