Pariya Meeros
Pariya Meeros

Reputation: 23

Regexextract text just before specific text Google Sheets

I need to extract the text that comes before the text District

Example String:

9224+H63, Ban Suan, Chon Buri District, Chon Buri 20000, Thailand

Valid Output should be Chon Buri District.

I tried =REGEXEXTRACT(K661,",\s([^\District]+") but it did not work.

Upvotes: 2

Views: 602

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626903

You can use

=REGEXEXTRACT(K661, ",\s*([^,]*?District)")

See the regex demo.

Details:

  • , - a comma
  • \s* - zero or more whitespaces
  • ([^,]*?District) - Capturing group 1: any zero or more chars other than a comma as few as possible and then a District fixed string.

Upvotes: 1

Related Questions