Results 1 to 20 of 20

Thread: Help with regular expression

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    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

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.