0

What would the regex be for matching the first column header in a csv file?

id,field1,field2
1,n/a,n/a
2,n/a,n/a
...

I just safely want to match id

2
  • What language/tool are you using? Regex can be different depending on flavour.
    – Toto
    May 12, 2022 at 18:46
  • @Toto the java 8 version, so the accepted answer would then be "^([^,]*)"g May 13, 2022 at 8:42

1 Answer 1

1
^([^,]*)/g

If you want to test on https://regex101.com/

  • ^ = start at the beginning of the string
  • [^,] = match anything except a comma
  • ([^,]*) = get everything from the beginning of the string to the comma
  • /g = don't return after first match

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .