By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

Regular expression to find all string literals in my code?

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Robin Tucker wrote:
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)

--
Larry Lard
Replies to group please

Nov 21 '05 #2

P: n/a
On 2005-05-03, Larry Lard <la*******@hotmail.com> wrote:

Robin Tucker wrote:
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

".*"


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


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.