Regex To Exract Text Inbetween 2 Selected Points ?

By phprepublican ·
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:


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>

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".

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Web Development Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums