I'm sure there is a simple solution, but I just seem to be missing it.
I need a regex to do the following:
asdf.txt;qwer
should match asdf.txt
"as;df.txt";qwer
should match as;df.txt
As you can see, I need to match up to the semi-colon, but if quotes exist(when there is a semi-colon in the value), I need to match inside the quotes. Since I am looking for a file name, there will never be a quote in the value.
My flavor of regex is C#.
Thanks for your help!
"[^"]+"(?=;)|[^;]+(?=;)
This matches text within double quotes followed by a semicolon OR text followed by a semicolon. The semicolon is NOT included in the match.
EDIT: realized my first attempt will match the quotes. The following expression will exclude the quotes, but uses subexpressions.
"([^"]+)";|([^;]+);
This should do you:
(".*"|.*);
It technically matches the semicolon as well, but you can either chop that off or just use the backreference (if C# supports backreferences)
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