I am writing some raw Regex code and testing them on online testers. I want to capture a list of strings right before a comma. Specifically, I want to capture up to 3 strings right before a comma. Ex.
string string string,
I want to capture "string string string" (including spaces).
How do I do that?
The safest way to capture the characters before the comma is: ^([^,]*)
Explanation:
^ Start of string
( Start of capture group
[^,]* Any number of any non-comma characters
) End of capture group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With