Author

Topic: Help me with a regex (Read 579 times)

hero member
Activity: 854
Merit: 503
|| Web developer ||
June 26, 2015, 11:58:35 AM
#5
You can use this pattern
Code:
/
(.*?)<\/div>/is

However, this will get tricky with nested quotes. Observing the forum thread HTML code, It looks like there is always a
after the div.quote element, so this may achieve the desired result for nested quotes.
Code:
/
(.*?)<\/div>

It may not work 100% of the time though, so you should always check your results.


Thanks , I used DOM Parser because Regex is not sure , and the result won't be 100% correct
Problem resolved !

Bitcoin Boy.
sr. member
Activity: 392
Merit: 268
Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ
June 26, 2015, 11:47:21 AM
#4
Is it necessary to use a regex? They can easily break (esp. ones like bitnanigan's hack that rely on extra tags) if the forum software gets an update that slightly changes the HTML generation behavior, or if the theme changes, as well as with some edge cases that the forum software may allow or create. You might have better luck with a DOM parser/HTML parser.
sr. member
Activity: 266
Merit: 250
June 26, 2015, 09:02:59 AM
#3
You can use this pattern
Code:
/
(.*?)<\/div>/is

However, this will get tricky with nested quotes. Observing the forum thread HTML code, It looks like there is always a
after the div.quote element, so this may achieve the desired result for nested quotes.
Code:
/
(.*?)<\/div>

It may not work 100% of the time though, so you should always check your results.

newbie
Activity: 50
Merit: 0
June 25, 2015, 11:57:54 PM
#2
Well you would have to get the source. use preg_match.

Test this out on any thread. Prob wont work for all but its a start, I need to look more into it.

Quote

$sForumThread = 'https://bitcointalksearch.org/topic/m.11689120

$sRequest = file_get_contents($sForumThread);

$sPattern = '|
(.*)
(.*)
|';

preg_match_all($sPattern, $sRequest, $sMatches);

var_dump($sMatches);

?>
hero member
Activity: 854
Merit: 503
|| Web developer ||
June 25, 2015, 11:31:12 PM
#1
Hello ,
I want to build a regex to get text between
Quote

I built this but seem not working well : (\[quote?.*\])(.*)(\[.*\])
Anyone could help me please to build one working for PHP .

Thanks for your time ,
Bitcoin Boy .


Note : I don't know if this is the right way to ask  Roll Eyes;
Jump to:
© 2020, Bitcointalksearch.org