haaglin Posted June 24, 2007 Share Posted June 24, 2007 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 More sharing options...
effigy Posted June 25, 2007 Share Posted June 25, 2007 You can do so with this method, or change your expression to PCRE and use lookarounds, e.g., (?<!="). Link to comment https://forums.phpfreaks.com/topic/56972-solved-need-help-with-exception-in-regex/#findComment-281977 Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 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 https://forums.phpfreaks.com/topic/56972-solved-need-help-with-exception-in-regex/#findComment-282878 Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 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 https://forums.phpfreaks.com/topic/56972-solved-need-help-with-exception-in-regex/#findComment-282881 Share on other sites More sharing options...
haaglin Posted June 26, 2007 Author Share Posted June 26, 2007 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 https://forums.phpfreaks.com/topic/56972-solved-need-help-with-exception-in-regex/#findComment-282933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.