I think there maybe a few ways to do this... One is

[EMAIL PROTECTED]@[EMAIL PROTECTED]

That basically says "find me the pattern where one non-at symbol is followed
by an at symbol followed by another non-at symbol"

So if you do 

<?php

$string = "@ one more T@@me for @ and i@ the Bl@@dy [EMAIL PROTECTED]";


$pattern = '/[EMAIL PROTECTED](@)[EMAIL PROTECTED]/';

$numMatch = preg_match_all($pattern, $string, $matches);

echo "numMatch: $numMatch\n";
print_r ($matches);

?>

numMatch: 3
Array
(
    [0] => Array
        (
            [0] =>  @ 
            [1] => i@ 
            [2] => [EMAIL PROTECTED]
        )

    [1] => Array
        (
            [0] => @
            [1] => @
            [2] => @
        )

)

Well, where that fails is when you have @'s at the beginning or end of the
string and that's easy enough to do.. So that would mean three searches...
There's probably a way to integrate them into one without loosing integrity,
but it depends on what kind of regexp libs you have, I reckon. It also
depends on what you really are trying to do with this search. Consider
str_replace, strpos and strtr as well.

Thanks,


Carl
-----Original Message-----
From: Al [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 16, 2005 3:54 PM
To: php-general@lists.php.net
Subject: regex question

What pattern can I use to match ONLY single occurrences of a character in a
string.

e.g., "Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@.

I only want the two occurrences with a single occurrence of "@".

@{1} doesn't work; there are 4 matches.

Thanks....

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to