I am writing a text parser, that needs to be able to remove comments from lines. I am using a rather simple language wherein all comments are initiated by a # character, and it would be simple to remove everything after that, but I have to deal with the possibility that the # is inside of a string.
My question, therefore, is, given a string such as
Value="String#1";"String#2"; # This is an array of "-delimited strings, "Like this"
How best can I extract the substring
Value="String#1";"String#2"; (note the trailing space)
Note that the comment may contain quotes, and also, the entire line may choose between " and ' deliminating, although it will be consistent over the entire line. This is known beforehand, if it is important. Quotes within the strings will be escaped by a \