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="name@domain.com"/>

 

How do i do that?

Link to comment
Share on other sites

How do i convert it to PCRE?

 

I tried this, and it didn't work..

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

Link to comment
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.
}

Link to comment
Share on other sites

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];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.