Regular expression to find all string literals in my code?

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
R

Robin Tucker

Hiya,

Regular expressions always do my gnads in - can anyone cook up a reg
expression to find all string literals in my code? I would like to put them
into a resource file for future translation :)

Thanks,



Robin
 
Robin said:
Hiya,

Regular expressions always do my gnads in - can anyone cook up a reg
expression to find all string literals in my code? I would like to put them
into a resource file for future translation :)

How about

".*"

(which means: a quote mark, any number of {any character}, a quote
mark)
 
How about

".*"

Regexes are greedy by default, so that wouldn't work, you'd match once from
the first quote in the file to the last. You really want...

".+?"
or
"[^"]+"

(plusses instead of stars since we probably don't want the empty string)

Although to be honest, neither of those will work correctly either.
I'm not sure that this problem is truly solvable by a regex. The problem
is correctly matching embedded quotes, things like

Dim s as string = "The first thing ""we"" do is kill all the ""lawyers"""

I'm not sure how to match that in a regex.

David
 
Back
Top