Regular Expressions in example

They have: 15 posts

Joined: Nov 2002

I have a problem with regular expressions:
I want to get text from

--
Jol lala blyszczysz jak szmaragd
--

Could anybody give me an example of doing this?


norito.civ.pl - ksi??ki i ksi??ki i jeszcze raz ksi??ki ^^

They have: 601 posts

Joined: Nov 2001

In what language? Perl, Python, PHP?

They have: 15 posts

Joined: Nov 2002

PHP. And don't send me to php.net, I've already been there Smiling

They have: 601 posts

Joined: Nov 2001

I'm not going to send you anywhere, but I'm going to wait around for someone who knows PHP to answer your post. Smiling

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

<?php
echo \"<html><body><pre>\n\";

$text = '<a name=\"xxx\">Jol lala blyszczysz jak szmaragd</a>';

if (preg_match('#<a.+>(.*?)</a>#Ui',
$text, $matches)) {
    // found something..
    echo \"pattern found\n\";
    print_r(
$matches);
}
else {
    // no pattern found
    echo \"no pattern found\n\";
}

echo \"</pre></body></html>\";
?>

output:
pattern found
Array
(
    [0] => Jol lala blyszczysz jak szmaragd
    [1] => Jol lala blyszczysz jak szmaragd
)
'The variable you'll want to use is $matches[1].

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 15 posts

Joined: Nov 2002

THX Mark Laughing out loud

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.