Regex Pattern for VB.Net String?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eBob.com

    Regex Pattern for VB.Net String?

    Is there a regex pattern which will match a VB.Net string? I.E. a regex
    which matches ...

    "this is a ""vb.net"" string"

    (I don't want three matches in this case, I want one.) I've come up with
    various solutions for the two-double-quotes-in-a-row problem but none of
    them have worked out.

    Thanks, Bob


  • rowe_newsgroups

    #2
    Re: Regex Pattern for VB.Net String?

    On Aug 19, 10:02 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
    Is there a regex pattern which will match a VB.Net string?  I.E. a regex
    which matches ...
    >
    "this is a ""vb.net"" string"
    >
    (I don't want three matches in this case, I want one.)  I've come up with
    various solutions for the two-double-quotes-in-a-row problem but none of
    them have worked out.
    >
    Thanks,  Bob
    Go grab Expresso and use it's graphical library to work through
    creating the Regex. It should get you where you need to be.



    Thanks,

    Seth Rowe [MVP]

    Comment

    • eBob.com

      #3
      Re: Regex Pattern for VB.Net String?

      Hi Seth,

      Thanks for responding. I am a HUGE fan of Expresso. But in my experience
      it has one major flaw - it hasn't made me any smarter! Expresso has helped
      me to eliminate all of the dumb ideas I've had so far. But I am not finding
      a pattern which is air tight. My latest idea, forgetting for the moment
      that almost any character can occur in a string, is ...
      "[\w("")]+"
      .... and that does match
      "some""mo""re"" "
      However, it also matches ...
      "some""mo"r e"""
      .... which of course it should not. I don't understand how it matches the
      first case and the second case. In the first case it does seem to be
      treating the double double-quotes as a single character, otherwise I'd get
      more than one match. But then in the second case it is perfectly happy to
      have one double-quote in the string which does not terminate the match.

      So despite Expresso I am still looking for a pattern which will match a VB
      string.

      Bob

      "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
      news:27ec5daf-0328-4f2d-8da9-7a143b7e42e3@x4 1g2000hsb.googl egroups.com...
      On Aug 19, 10:02 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
      Is there a regex pattern which will match a VB.Net string? I.E. a regex
      which matches ...
      >
      "this is a ""vb.net"" string"
      >
      (I don't want three matches in this case, I want one.) I've come up with
      various solutions for the two-double-quotes-in-a-row problem but none of
      them have worked out.
      >
      Thanks, Bob
      Go grab Expresso and use it's graphical library to work through
      creating the Regex. It should get you where you need to be.



      Thanks,

      Seth Rowe [MVP]



      Comment

      • jamil@onepost.net

        #4
        Re: Regex Pattern for VB.Net String?

        On Wed, 20 Aug 2008 12:17:04 -0400, "eBob.com"
        <eBob.com@total lybogus.comwrot e:
        >Hi Seth,
        >
        >Thanks for responding. I am a HUGE fan of Expresso. But in my experience
        >it has one major flaw - it hasn't made me any smarter! Expresso has helped
        >me to eliminate all of the dumb ideas I've had so far. But I am not finding
        >a pattern which is air tight. My latest idea, forgetting for the moment
        >that almost any character can occur in a string, is ...
        >"[\w("")]+"
        >... and that does match
        >"some""mo""re" ""
        >However, it also matches ...
        >"some""mo"re"" "
        >... which of course it should not. I don't understand how it matches the
        >first case and the second case. In the first case it does seem to be
        >treating the double double-quotes as a single character, otherwise I'd get
        >more than one match. But then in the second case it is perfectly happy to
        >have one double-quote in the string which does not terminate the match.
        >
        >So despite Expresso I am still looking for a pattern which will match a VB
        >string.
        >
        >Bob
        Forget about trying to do this with a single regular expression.
        You're not going to have success.

        What I suggest you do is split this up into three steps:

        1. All VB strings start and end with double quotes, so remove them.
        2. With the remaining text, temporarily replace all double quotes
        with other characters. So, "some ""more"" text" will become
        "some \quotemore\quot e text".
        3. Test if the text is now a valid VB string. You can do this with
        a simple regular expression like: ^(?!.*").*$
        This that expression does not match, it's not a valid string.

        You have all text for the string now if the text was a valid string.

        You really do not have another choice, since you cannot use balanced
        group matching (the beginning " is identical to the ending ", so you
        cannot differentiate starting and ending strings unless you replace
        all "" characters with something else).

        Comment

        Working...