#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    199
    Rep Power
    43

    Arrow [SOLVED] Finding "Strings" (enclosed by quoetes) using RegEx


    Hello All,

    I am trying to find all strings (enclosed by quotes) using a regular expression.

    My first attempt was:
    ".*"

    But that was too greedy...

    So my second attempt was:
    "[^"]*"

    ... which seemed to work... until I realized that it failed for escaped strings...

    so I am trying to make a regular expression that will handle this case:

    " my cool expression handles \"escaped quotes\" too!"

    AWESOME IDEA UPDATE: I could have my regular expression look for \\" OR ^". How could I do that?

    AWESOME ANSWER UPDATE: I found my answer...
    "(\\"|[^"])*" seems to work... Just letting you know incase someone else has the same problem.

    Thanks!
    Last edited by videoediting; November 23rd, 2008 at 08:45 PM.
  2. #2
  3. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    938
    But what happens if you want to escape the '\'?
    Like this:
    Code:
    Hi, "first  an escape \" and this is a backslash: \\", and we're outside the quotes again.

IMN logo majestic logo threadwatch logo seochat tools logo