1

I have some input strings where I want to just get the city names (Brighton, Singapore, Austin, San Francisco)

Brighton, United Kingdom
Singapore
Austin, TX, USA
San Francisco, CA, USA

I've tried doing this regex (.*),? but it matches the whole string, disregarding the comma. How can I only match up till the first comma if it exists?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Jayndoodle
  • 53
  • 5

1 Answers1

0

You can use

(?m)^[^\r\n,]+

See the regex demo.

Details

  • (?m)^ - start of a line
  • [^\r\n,]+ - one or more chars other than CR, LF and a comma.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563