Regex To Exract Text Inbetween 2 Selected Points

sunny_pro

New member
Joined
Jun 18, 2017
Messages
86
Points
0
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>



Php Folks,


What is the regex to extract the title, meta keywords, meta descriptions and the content text (without all the tags such as html tags, dhtml tags, xml tags, javascript tags, etc.) ?

I actually, prefer one regex to extract title, another to extract meta keywords, another to extract meta descriptions and finally another to extract the content text.

That way, I can make use of each separately when I don't want to extract all (title, description, etc.).



If you know of php functions, other than regex that do what I want, then say so by writing: OFF TOPIC.

Thanks for your help!
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,489
Points
113
You may want to use the "Document Object Model" instead. Or look around and see if you can find a PHP library you like for handling and parsing HTML pages.
 

Netman82

New member
Joined
Feb 2, 2018
Messages
8
Points
0
Regex expression is different on every situation. one of the simplest ways is:
(?<=Leftt Side).*(?=Right Side)

For example to get the Title on the provided code:
(?<=\<title\>).*(?=\<\/title\>)
 
Older threads
Replies
3
Views
1,707
Replies
3
Views
1,508
Replies
3
Views
1,543
Latest threads
Replies
1
Views
43
Replies
0
Views
54
Replies
0
Views
48
Replies
1
Views
58
Replies
3
Views
129
Recommended threads

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top