0

find many

keyword="text with quotes "

but none ignoring double or single quotes keyword="text with quotes " or keyword='text with quotes'

i produced following code but it does not work

function GENERIC_FIND_KEYWORD_AND_QUOTED_TEXT($STR)
{ // keyword=" " surrounded by whitespace or non symbol strings (outside off a-zA-Z0-9_

// using (key1=' embeded qwuotes' AND key2=" embeded qwuotes") !key3=' embeded qwuotes' key4=" embeded qwuotes" ... // as input string

   $res=preg_match_all('/[a-zA-Z0-9_]{1,}=("((?:[^\\\]*?(?:\\\")?)*?)"|\'((?:[^\\\]*?(?:\\\')?)*?)\')/', $str, $arr, PREG_SET_ORDER);

print_r($arr);echo ""; // would

like an array like array('key1'=>'text','key2'=>"text" ,'key3'=>'text','key4'=>'text','key5'=>'text') }

It does not work but is suppoed to match multiple times per line on a symbol (defined as [a-zA-Z0-9_]{1,} endded with = a single or double quote the quoted string should be detected ignoring quoted quotes inbetween the single or doubled quotes....

the keyword is not surrounded by whitespace as in XML but with any non symbol characters or whitespace..... ex I want to verify all mysql keywords and matching constructs ...

where the ? makes it a keyword of special interest

input output structure:

input: little or no control, I do not have an idea what the user is going to enter the idea is to be s generic as possible especially ; considering all in the quoted strings

keyword="bla 'bla "" dfddfd" or keword2='dfdfd " dsdsdfsdfdf'

sure it must be stated correctly and consistently ....

output: array ( keyword =>"bla 'bla "" dfddfd", keyword2=>'dfdfd " dsdsdfsdfdf', ...)

secondly:(slightly different related problem) I would like to filter special tagged keywords to replace them later(need unchanged components)

keyword="bla 'bla "" dfddfd" or/and _keword2='dfdfd " dsdsdfsdfdf'

where I only get the taged components _*="...." filtered (suppose it is more efficient changing the match patern then loop through all array elements to find the secondary keyword patern... \

output: array ( _keyword2=>'dfdfd " dsdsdfsdfdf', ...)

user1557188
  • 41
  • 1
  • 5
  • Can you give us a full input example (hopefully one that you have difficultly with) and then the full ideal result data structure (`$arr`?) of what the input would create? – ghbarratt Jul 28 '12 at 16:37

1 Answers1

0

RegEx:

/([^ ]+)\=((\"([^"]+)\")|(\'([^']+)\'))/
Knarf
  • 1,282
  • 3
  • 12
  • 31