Home > OS >  Combining LEFT, SEARCH and REGEXREPLACE
Combining LEFT, SEARCH and REGEXREPLACE

Time:06-26

So, I'm helping out someone, and I'm trying to extract only the name of the cancer in the column, without including "Deaths -".

In Column A, the entries all have this pattern, each string below being in it's own separate row...

Deaths - Prostate cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Breast cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Testicular cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Non-melanoma cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Tracheal, bronchus, and lung cancer - Sex: Both - Age: Age-standardized (Rate)

I've been able to extract the name of the cancer, including removing the word "cancer" with this LEFT and SEARCH formula below...

=LEFT(A2, SEARCH("cancer", A2)-1)

Resulting in the following...

Deaths - Breast 
Deaths - Testicular 
Deaths - Non-melanoma 
Deaths - Tracheal, bronchus, and lung

But, I can't seem to combine REGEXREPLACE with LEFT and SEARCH in one formula to also take out "Deaths" and the - (dash), leaving only the name of the cancer.

So, the desired result is below...

Breast 
Testicular 
Non-melanoma 
Tracheal, bronchus, and lung

Thanks for any help you can provide.

CodePudding user response:

try simple:

=INDEX(IFNA(REGEXEXTRACT(A1:A6, "- (. ) cancer")))

enter image description here

  • Related