Page 1 of 1

I want to match words which have special characters in it...

Posted: Wed Feb 01, 2006 8:45 am
by raghavan20
I expect to match
rough**ly
tha&&t
docum//ents

Code: Select all

<?php

$input = <<<EOD
Character data is rough**ly all the (non-markup) contents2343 of XML docum//ents, including white234324space 

between tags. Note tha&&t the XML par2756724ser does not add or remove any (whitespace), it is up to the33333 

application (you) to decide whether whitespace5555 is significant. 
EOD;

echo preg_match_all("/\b\w+(\W+)\w+\b/mi", $input, $matches)."<br />";
print_r($matches);

?>
but this returns...

Code: Select all

Array
(
    [0] => Array
        (
            [0] => Character data
            [1] => is rough
            [2] => ly all
            [3] => the (non
            [4] => markup) contents2343
            [5] => of XML
            [6] => docum//ents
            [7] => including white234324space
            [8] => between tags
            [9] => Note tha
            [10] => t the
            [11] => XML par2756724ser
            [12] => does not
            [13] => add or
            [14] => remove any
            [15] => whitespace), it
            [16] => is up
            [17] => to the33333
            [18] => application (you
            [19] => to decide
            [20] => whether whitespace5555
            [21] => is significant
        )

    [1] => Array
        (
            [0] =>  
            [1] =>  
            [2] =>  
            [3] =>  (
            [4] => ) 
            [5] =>  
            [6] => //
            [7] =>  
            [8] =>  
            [9] =>  
            [10] =>  
            [11] =>  
            [12] =>  
            [13] =>  
            [14] =>  
            [15] => ), 
            [16] =>  
            [17] =>  
            [18] =>  (
            [19] =>  
            [20] =>  
            [21] =>  
        )

Posted: Wed Feb 01, 2006 9:23 am
by feyd

Code: Select all

#\b[A-z]*[\*/&]+[A-z]+#
possibly... can't test it right now..

Posted: Wed Feb 01, 2006 9:33 am
by raghavan20
but I want to check for any special character not specifically for *,/ and & characters...

Posted: Wed Feb 01, 2006 10:06 am
by feyd
:roll: try this then..

Code: Select all

#\b[A-z]*[^\sA-z0-9]+[A-z]+[^\sA-z0-9]*#

Posted: Wed Feb 01, 2006 10:15 am
by raghavan20
This is the output for your regex

Code: Select all

Array
(
    [0] => Array
        (
            [0] => rough**ly
            [1] => non-markup)
            [2] => docum//ents,
            [3] => tha&&t
        )

)

Posted: Wed Feb 01, 2006 10:19 am
by raghavan20
This worked...#\b[a-z]+([^a-z0-9\s]+)[a-z]+\b#i

Code: Select all

Array
(
    [0] => Array
        (
            [0] => rough**ly
            [1] => non-markup
            [2] => docum//ents
            [3] => tha&&t
        )

    [1] => Array
        (
            [0] => **
            [1] => -
            [2] => //
            [3] => &&
        )

)