Regular expression to find all string literals in my code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Tucker

    Regular expression to find all string literals in my code?

    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


  • Larry Lard

    #2
    Re: Regular expression to find all string literals in my code?


    Robin Tucker wrote:[color=blue]
    > 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[/color]
    put them[color=blue]
    > into a resource file for future translation :)[/color]

    How about

    ".*"

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

    --
    Larry Lard
    Replies to group please

    Comment

    • David

      #3
      Re: Regular expression to find all string literals in my code?

      On 2005-05-03, Larry Lard <larrylard@hotm ail.com> wrote:[color=blue]
      >
      > Robin Tucker wrote:[color=green]
      >> 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[/color]
      > put them[color=green]
      >> into a resource file for future translation :)[/color]
      >
      > How about
      >
      > ".*"[/color]

      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




      Comment

      Working...