Results 1 to 20 of 20

Thread: Help with regular expression

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with regular expression

    Quote Originally Posted by Gourmet View Post
    Not applicable, this will too slow. The solution must dance not from keywords but from delimiters. They are known and have very limited number. All other character sequences are keywords.
    QStringList keywords = inputTextLine.split( QRegExp( all delimiters or'd) )

    Ta freaking Da.
    No one is trolling you here, Six is correct you keep complaining, and making excuses. If you are not willing to learn via trial and error you will not learn at all. thus making me wonder why you are taking a programming class

  2. #2
    Join Date
    Apr 2011
    Posts
    31
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Help with regular expression

    I'm not taking programming class. I'm experienced enough in C/C++ and OOP after hundreeds of thousands working lines since 1989. Currently I debug up to 400-500 lines of C++ code per day using wide set of Qt classes. But I never used Perl-like regular expressions. That is why I asked for help but not to try "teach" me something... If I told - I need this kind of solution - that means only: I need this kind of solution. Not other kind but THIS KIND. A pattern to find keyword in string with known delimiters. I did not ask for help in coding. All other suggestions I could engineer by myself and not ask for help. If the solution I asked for is impossible - just tell: "it is impossible". Then I'll find other solution by myself without help. Or tell: "Sorry I cant' help you".

    Do not drop a wood bar if you have lifebuoy - drop bar only if you don't have lifebuoy. And notify about it mandatory. Otherwise drop lifebuoy but not bar. And never shout: "Teach swim yourself".
    Last edited by Gourmet; 10th August 2011 at 16:19.

  3. #3
    Join Date
    Jul 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with regular expression

    I'm going to deal with this lack of appreciation, Six and I have given you multiple way to do this, If you are not going to even try then I'm done.

    I learned Regex on the fly, took me less than one hour to pick up on the simplicity of regexs.

    Step one: split the code line (write one regex for this, my previous post)
    Step two: see if a word is a keyword( write another regex for this )
    Step three move on to next word or line. ( loops!)

    Qt Code:
    1. Execution Time(sec.):
    2. 0.000009
    3.  
    4. Raw Match Pattern:
    5. (.*)(\"|\'|\;|\.|\,|\:|\(|\)|\{|\}|\[|\])(.*)?
    6.  
    7. Match Pattern Explanation:
    8. The regular expression:
    9.  
    10. (?-imsx:(.*)("|'|;|\.|,|:|\(|\)|\{|\}|\[|\])(.*)?)
    11.  
    12. matches as follows:
    13.  
    14. NODE EXPLANATION
    15. ----------------------------------------------------------------------
    16. (?-imsx: group, but do not capture (case-sensitive)
    17. (with ^ and $ matching normally) (with . not
    18. matching \n) (matching whitespace and #
    19. normally):
    20. ----------------------------------------------------------------------
    21. ( group and capture to \1:
    22. ----------------------------------------------------------------------
    23. .* any character except \n (0 or more times
    24. (matching the most amount possible))
    25. ----------------------------------------------------------------------
    26. ) end of \1
    27. ----------------------------------------------------------------------
    28. ( group and capture to \2:
    29. ----------------------------------------------------------------------
    30. " '"'
    31. ----------------------------------------------------------------------
    32. | OR
    33. ----------------------------------------------------------------------
    34. ' '\''
    35. ----------------------------------------------------------------------
    36. | OR
    37. ----------------------------------------------------------------------
    38. ; ';'
    39. ----------------------------------------------------------------------
    40. | OR
    41. ----------------------------------------------------------------------
    42. \. '.'
    43. ----------------------------------------------------------------------
    44. | OR
    45. ----------------------------------------------------------------------
    46. , ','
    47. ----------------------------------------------------------------------
    48. | OR
    49. ----------------------------------------------------------------------
    50. : ':'
    51. ----------------------------------------------------------------------
    52. | OR
    53. ----------------------------------------------------------------------
    54. \( '('
    55. ----------------------------------------------------------------------
    56. | OR
    57. ----------------------------------------------------------------------
    58. \) ')'
    59. ----------------------------------------------------------------------
    60. | OR
    61. ----------------------------------------------------------------------
    62. \{ '{'
    63. ----------------------------------------------------------------------
    64. | OR
    65. ----------------------------------------------------------------------
    66. \} '}'
    67. ----------------------------------------------------------------------
    68. | OR
    69. ----------------------------------------------------------------------
    70. \[ '['
    71. ----------------------------------------------------------------------
    72. | OR
    73. ----------------------------------------------------------------------
    74. \] ']'
    75. ----------------------------------------------------------------------
    76. ) end of \2
    77. ----------------------------------------------------------------------
    78. ( group and capture to \3 (optional
    79. (matching the most amount possible)):
    80. ----------------------------------------------------------------------
    81. .* any character except \n (0 or more times
    82. (matching the most amount possible))
    83. ----------------------------------------------------------------------
    84. )? end of \3 (NOTE: because you're using a
    85. quantifier on this capture, only the LAST
    86. repetition of the captured pattern will be
    87. stored in \3)
    88. ----------------------------------------------------------------------
    89. ) end of grouping
    90. ----------------------------------------------------------------------
    91.  
    92. $matches Array:
    93. (
    94. [0] => Array
    95. (
    96. [0] => hello:goodbye
    97. )
    98.  
    99. [1] => Array
    100. (
    101. [0] => hello
    102. )
    103.  
    104. [2] => Array
    105. (
    106. [0] => :
    107. )
    108.  
    109. [3] => Array
    110. (
    111. [0] => goodbye
    112.  
    113. **ignore "?-imsx:" that is looking at the possible flags you can set
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacks916; 10th August 2011 at 17:16. Reason: updated contents

  4. #4
    Join Date
    Apr 2011
    Posts
    31
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Help with regular expression

    Looks like you all did not read problem carefully... Your suggestions are not applicable. The main task is highlight keywords in the text. That means - not the presence of word in text must be confirmed. Instead the position of text to highlight must be encountered. Split list is absolutely useless in this case. It only can confirm or decline the presence of keyword inside text. But cannot give it's index.

    Again - I have a list of keywords. They must be found in QString to know their positions inside this string. The set of delimiters is also known. Anybody more familiar can help?

    BTW: looks like both previous "helpers" even don't know how highlighter in Qt works...
    Last edited by Gourmet; 11th August 2011 at 11:51.

  5. #5
    Join Date
    Jul 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with regular expression

    I like how you just throw out what we have inputted. good luck.

  6. #6
    Join Date
    Apr 2011
    Posts
    31
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Help with regular expression

    Your input does not give me anything useful except possibly this: (.*)(\"|\'|\;|\.|\,|\:|\(|\)|\{|\}|\[|\])(.*)?
    But this is subject to check.

Similar Threads

  1. Regular Expression Problem
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2009, 09:41
  2. set a regular expression on QTextEdit
    By mattia in forum Newbie
    Replies: 3
    Last Post: 27th March 2008, 10:16
  3. Regular expression in QLineEdit?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 1st October 2007, 10:58
  4. Find with Regular Expression?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 14:44
  5. How to get a QString from a file (use regular expression)
    By fengtian.we in forum Qt Programming
    Replies: 16
    Last Post: 31st May 2007, 11:06

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.