Results 1 to 8 of 8

Thread: [RESOLVED] Regex? Get content within " "

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Resolved [RESOLVED] Regex? Get content within " "

    I have a string that contains text similar to this:
    Code:
    hello "test" "another test\"" "ok"
    I want it to split in an output like this:
    Code:
    test
    another test\"
    ok
    In this thread http://www.vbforums.com/showthread.php?t=576158 (?<=[^\\]|^)"" was used to remove quotes that don't have a \ before them. Maybe it can be adapted to be used as a split? But I am unsure on how to do so.

    Thanks in advance.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Regex? Get content within " "

    'hello' gets deleted because it's not in double quotes?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Re: Regex? Get content within " "

    Yes.

  4. #4
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex? Get content within " "

    I'm not a genius with regexp, but this should work:

    Code:
    "[a-z ]*\\?"?"
    Although, you will have to remove the beginning and ending quotation marks:

    Code:
    String = String.Remove(0,1)
    String = String.Remove(String.Length - 1, 1)

  5. #5
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Regex? Get content within " "

    What happens if a string isn't terminated properly with double quotes? ie:

    Code:
    this is" just a "test" "example \"

  6. #6
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex? Get content within " "

    Lol, didn't take that into consideration =P

    There need to be clearer rules in case something like that occurs. Should it print:

    " just a "test"
    "example \"

    Or should it just remove one of the quotation marks? Which one?

    I.e.

    "test"
    "example \"

    or

    " just a test"
    "example \"

    etc..

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Posts
    70

    Re: Regex? Get content within " "

    If it is something like this:
    "hello " hi"
    You should get
    hello
    (with a space after hello) It should return the first set of double quotes.

    If it is: "hello \" it should return: hello \
    If that is even possible without making it extremely complicated while still being able to maintain:
    "hello \" hi"
    Being: hello \" hi
    Otherwise if that is to complicated make it return nothing.

  8. #8
    Addicted Member
    Join Date
    Jul 2009
    Posts
    138

    Re: Regex? Get content within " "

    Would this be more suited to your needs?

    Code:
    "[a-z \\]*"?[a-z \\]*"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width