Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Regexextract to get a text in the middle of string

$
0
0

SAMPLE SHEET

I have data in a column in this format:

1 P01 - Product Name here - PAID IN FULL

2 P02 - Product2 Name here - PARTIALLY PAID 20

1 P03 - Product2 Name here

I've been trying to extract just the middle part, i.e. the code & product name, using regex. This bit P03 - Product2 Name here The dash between the code & name should be left as is.

I managed to remove the first bit, 1.... etc, but I can't seem to get rid of the last bit - PAID IN FULL etc. This last dash should also go.

Using Regexreplace

=ARRAYFORMULA(TRIM(REGEXREPLACE(A2:A3, "^(\d)\s", "")))

result: P01 - Product Name here - PAID IN FULL

Regexextract

=arrayformula(REGEXEXTRACT(A2:A3, "[^(\d)\s].*"))

result: P01 - Product Name here - PAID IN FULL

=arrayformula(REGEXEXTRACT(A2:A3, "[^(\d)\s+].*[^-A-Z$]"))

result: P01 - Product Name here - PAID IN

Extract & replace

=arrayformula(REGEXEXTRACT(A2:A4, "[^(\d)\s+].*[^-$]"))

result:enter image description here

Same above formula edited a bit to remove ^ before - :

=arrayformula(REGEXEXTRACT(A2:A4, "[^(\d)\s+].*[-$]"))

result:enter image description here


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>