Results 1 to 4 of 4

Thread: Help with a regular expression.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Help with a regular expression.

    Hi there guys, I am trying to put together a regular expression for pulling out data from the html below. The text I am interested in, is in line 3,22, and "href" of line 25. I have have put together this regular expression for line 25 and it works perfectly
    Qt Code:
    1. <a\\s+class=\"linkDetails\"\\s+href=\"(.*)\"\\s+target=\"_blank\"\\s+title=\"Details\">
    To copy to clipboard, switch view to plain text mode 
    I would like to extend the above regular expression to retrieve line 3 and 22 as well and through the use of QRegExp::cap(), I can store the data accordingly in a QStringList. I could use a little help with extending the R.E.
    Qt Code:
    1. <tr class="gridDetails">
    2. <td style="width: 70px;">
    3. R01170512A
    4. </td>
    5. <td>
    6.  
    7. Gloves;nytrile, heavy duty;10
    8. </td>
    9. <td style="width: 100px; padding-right: 10px;">
    10. Clothing - PPE &amp; Accessories
    11. </td>
    12. <td style="width: 70px; padding-right: 10px;">
    13. 2017/03/15
    14. </td>
    15. <td style="width: 70px; padding-right: 10px;">
    16. 3/15/2017 10:00:00 AM
    17. </td>
    18. <td style="width: 70px; padding-right: 10px;">
    19. 2017/03/09
    20. </td>
    21. <td style="width: 70px; padding-right: 10px;">
    22. 3/9/2017 9:59:27 AM
    23. </td>
    24. <td style="width: 10px; padding-right: 5px; padding-left: 5px;">
    25. <a class="linkDetails" href="/web1/ProcurementPortal/RFQ/Details/123668" target="_blank" title="Details"> </a>
    26. </td>
    27. </tr>
    28. <tr class="gridDetails">
    29. <td style="width: 70px;">
    30. R01170554A
    31. </td>
    32. <td>
    33.  
    34. Overall trousers;white;34/87cm
    35. </td>
    36. <td style="width: 100px; padding-right: 10px;">
    37. Clothing - PPE &amp; Accessories
    38. </td>
    39. <td style="width: 70px; padding-right: 10px;">
    40. 2017/03/15
    41. </td>
    42. <td style="width: 70px; padding-right: 10px;">
    43. 3/15/2017 10:00:00 AM
    44. </td>
    45. <td style="width: 70px; padding-right: 10px;">
    46. 2017/03/09
    47. </td>
    48. <td style="width: 70px; padding-right: 10px;">
    49. 3/9/2017 9:59:27 AM
    50. </td>
    51. <td style="width: 10px; padding-right: 5px; padding-left: 5px;">
    52. <a class="linkDetails" href="/web1/ProcurementPortal/RFQ/Details/123667" target="_blank" title="Details"> </a>
    53. </td>
    54. </tr>
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Help with a regular expression.

    Can't you just parse the file and pick the required tags.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with a regular expression.

    I tried using QDom classes to parse but it turns out that QDom classes don't work with html, so I tried using external libs like libxml++ and libxml2 but I got a bunch of linker errors I could not figure out. What can I use to parse html in Qt? thanking you in advance.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Help with a regular expression.

    See the answer at this stackoverflow link on using QXmlQuery to parse HTML.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Problem regarding regular expression
    By aaditya190 in forum Newbie
    Replies: 2
    Last Post: 12th December 2013, 20:29
  2. Regular expression
    By aguleo in forum Newbie
    Replies: 0
    Last Post: 25th January 2013, 15:00
  3. Regular expression
    By QFreeCamellia in forum Newbie
    Replies: 8
    Last Post: 30th December 2011, 22:34
  4. Regular expression help!
    By ConkerX in forum Qt Programming
    Replies: 10
    Last Post: 31st August 2011, 15:47
  5. Help with regular expression
    By Gourmet in forum General Programming
    Replies: 19
    Last Post: 11th August 2011, 15:04

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.