Results 1 to 8 of 8

Thread: RegExpr

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default RegExpr

    Hello, I have to define a reg expression and I read one way is to use verbatim keyword to avoid to use backslash for escape caracter (I think it's more thin). But maybe It's not so better. How do use it? I have to define something line [^abc\n"]* and I'm confused now:
    Qt Code:
    1. Regex regexpr = new Regex(@"[^abc\n"]*");
    To copy to clipboard, switch view to plain text mode 
    is it correct? How can I insert " inside verbatim string? It gets error because it expects the end of string......I just write it in C# but maybe will be the same with c++...
    thanks.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: RegExpr

    Simply escape the backslash with another backslash ([^abc\\n"]).

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: RegExpr

    sorry but it I have:
    Qt Code:
    1. string inputString = @"1992
    2. 188";
    To copy to clipboard, switch view to plain text mode 
    if I have ([^abc\\n"]) the newline is recognized; and it shouldn't be; the newline isn't recognized if I have ([^abc\n"]) with one \
    I thought that was right; my question was on "
    Sorry but with some prove, I see that to use " inside literal with meaning I need, it should be double quote ( ""):
    Qt Code:
    1. string inputString = @"19""92"
    2. regXep = ......([^abc\n""])
    To copy to clipboard, switch view to plain text mode 
    In this way I have string 19"92 and it doesn't recognized in one token but in two: 19 and 92.
    Is right? (for \n: it seems works without \\ but with only one)....
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: RegExpr

    Escape the quote with an escaped backslash as well
    [^abc\n\\"]

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: RegExpr

    Quote Originally Posted by wysota View Post
    Escape the quote with an escaped backslash as well
    [^abc\n\\"]
    It doens't work with \\": compiler see the " as the " of the end of verbatim string......and it gets error...
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: RegExpr

    Lose the verbatim string. You're escaping special characters to avoid it.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: RegExpr

    Hello, I've got this problem here:
    Qt Code:
    1. @"(?<first>[a-z]+)?(?<second>hello\(\))"
    To copy to clipboard, switch view to plain text mode 
    I just want recognize hello() in <second> group;
    <first> can recognize:
    ffddfhello
    ffffhello
    helloWorld
    hello
    helloffffff
    But I can't recognized hello() in the second group........when input string is hello() I can see that hello (and only hello) is recognize by first (instead hello() must be recognized by second enterely....)
    Is there an error please?
    Regards

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: RegExpr

    hi, is there a way to say in the <first> :"don't recognize 'hello()' "?
    Regards

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.