Jump to content

[SOLVED] need help with exception in regex


haaglin

Recommended Posts

Hi.

 

I have this expression to find any emails in a document:

 

$reg = '([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)';
while( eregi($reg, $content, $regs ) ) {		
       //do some stuff with te found address in $content.
}

 

This works fine, but i want it to find all emails except those inside input tags (and only input tags) , like this one:

<input type="text" value="[email protected]"/>

 

How do i do that?

Link to comment
https://forums.phpfreaks.com/topic/56972-solved-need-help-with-exception-in-regex/
Share on other sites

Almost got it i think, but it still returns the emails, except for the first letter.

 

$reg = '/(?<!=")(([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+))/';
while( preg_match($reg, $content, $regs ) ) {		
       //do some stuff with te found address in $content.
}

Solved it. This it what i did:

 

$reg = '/([[:alnum:]_\.\-]+)(\@[[:alnum:]\.\-]+\.+)([[:alnum:]\.\-]+)/';
preg_match ($reg, $content, $regs );
$mail = $regs[0];
while( preg_match ("/(?<!value=\")$mail/", $content, $regs ) ) {		
        $content =  preg_replace("/(?<!value=\")$mail/", $replace, $content );
preg_match ($reg, $content, $regs );
$mail = $regs[0];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.