#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0

    Regex To Exract Text Inbetween 2 Selected Points


    RegExp Exps (Regular Expression Experts),


    What is the regex to extract your desired text inbetween 2 tags such as the opening html tag and the closing.
    Should work for other tags too such as javascript, xml, dhtml, css, etc.

    Imagine that, I'm on a webpage that looks like this in the source code:

    <html>
    <head><title>Article</title></head>

    <body>
    Regex is too complicated to learn!<br>
    Why on earth could not the inventors build it simpler so it is easier to learn ?<br>
    Oh boy, oh boy!<br>
    </body>
    </html>

    Now imagine, I want to extract the text inbetween the <title< and </title>.
    and likewise extract inbetween <body> and </body>.
    Now, what is the regex to do that ?
    Ok, there maybe regex to extract the title and another to extract the meta keywords and another to extract the meta descriptions and so on from a page.
    But, I ain't interested in the specific regex. I just need to learn the general one that is capable of extracting text inbetween 2 points. In the regex, I should point out (1st param) what the starting point is. And, point out (in the 2nd param) what the ending point is.
    And, in this thread, I ain't interested in extracting text inbetween tags either. I'm actually interested in extracting text from inbetween 2 points whether the starting point is some tag (html, javascript, etc.) or mere simple text.
    Another example ....

    My name is Bert. What is your's ?. What ! You don't have a name ? You mus be kidding ?
    Imagine in this example, the starting point is the 2nd "is" and the ending point is the 2nd "?".
    And so, the regex should allow me to pick the starting and ending point and any offsets.

    If there is a php function that does this then you can mention this too. But, mention it under "OFF TOPIC".
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,269
    Rep Power
    4193
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    Originally Posted by kicken
    Oh! The regex or the php function ?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    something like this?

    (<title>.*?</title>|<body>.*?</body>|\R)(*SKIP)(*F)|.

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    (.*?is){2}(.*?\?.*?)\?.*

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    .*?is.*?(is.*?\?.*?\?).*

  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    845
    Rep Power
    0
    User4589,

    I need to extract with php and not some .exe tool. As I need to fetch pages with cURL and then get php to do the extracting from the fetched pages.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2017
    Posts
    10
    Rep Power
    0
    use the same regex code in php

IMN logo majestic logo threadwatch logo seochat tools logo