Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Catching strings outside of quotes(Regex)

Discussion in 'Scripting' started by RoeeHerzovich, Sep 19, 2020.

  1. RoeeHerzovich


    Apr 12, 2020
    I wanna catch strings outside of quotes using regex.
    For example:
    I wanna catch that "But not that" and I want that one too!

    So far I've gotten to that:

    it catches all CHARACTERS outside of quotes, meaning that if I do:

    Hello there "how are you"
    it will not catch hello world but will catch
    H e l l o t h e r e
    anyone got any idea how to make it catch the entire string?

    I appreciate the help :)
  2. Yoreki


    Apr 10, 2019
    I cant help with regex, but if other solutions are allows this should do the same:
    Add a token string to the beginning of your string. Split() the string at quotation marks. For each uneven index of the resulting array, clean the contents to an empty string. Now remove the token string from the first index again and rebuild the string. The result should be the same string minus anything in quotation marks.

    The token string only exists to guarantee that the string does not start with a quotation mark. So it makes sure that the text in quotes always ends up on uneven indices. The token can be anything that does not normally appear in the string.
    May break on unusual usage of quotation marks tho, as it assumes that the unwanted text is always properly encapsulated with one quotation mark in front and after, and no others occuring in the string.
  3. RoeeHerzovich


    Apr 12, 2020

    Thank you for your answer, however, I found a solution:


    (will not work with floating numbers, it will mark both digits but not floats, however a small modification would do)