Page 1 of 1

Extract values between "" or " for specif

Posted: Wed Sep 05, 2007 1:55 pm
by jaysaiom
Hi,

I am trying to match substrings and if they match extract the complete string encapsulated by either actual quotes (") or encoded ". At runtime i generate the regex with the list of substring that need to match. In the example below, the regex generated looks for substrings - templates1 and templates2 enclosed by " or " Note that the given substring will be encapsulated by " only or " only but not combination of them.

Regex pattern - (?<replacestrings>"(.*templates1.*)"|"(.*templates1.*)"|"(.*templates2.*)"|"(.*templates2.*"))

Sample Source - <document documentid=\"100\" documentname=\"Office\" xmlns=\"\"><fields><fieldset id=\"field1\" label=\"office\"><field id=\"1\" value=\"<test office:folder="menu"office:filepath="top"office:template="office/templates1/folders/files/container" office:type="group" office:officefolder="office/templates2/test/folders/file"><field id=\"metatadata\" value=\"\" type=\"text\" label=\"metatadata\" property=\"\" /></fieldset></fields><devices /></edit>


Matches
1. office/templates1/folders/files/container
2. office/templates2/test/folders/file

Any clues to correct regex?

Thanks,

Posted: Fri Sep 07, 2007 6:40 am
by GeertDD
The strings that you are currently matching are encapsulated by ". So the exact problem isn't actually clear to me...

Replace &quot; with "

Posted: Sat Oct 20, 2007 4:07 am
by regexpert
If I were First I replaced " s with " and continue parsing replaced string;


first

$str = str_replace('"','"',$str);

and then preg_match;

so on...