Extract values between "" or " for specif

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jaysaiom
Forum Newbie
Posts: 1
Joined: Wed Sep 05, 2007 1:51 pm

Extract values between "" or " for specif

Post 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,
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Post by GeertDD »

The strings that you are currently matching are encapsulated by ". So the exact problem isn't actually clear to me...
regexpert
Forum Newbie
Posts: 7
Joined: Sat Oct 20, 2007 3:41 am

Replace &quot; with "

Post 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...
Post Reply