On Monday, February 24, 2020 at 9:54:43 AM UTC-8, Miguel Perez wrote:
>
> Thank you, ThePorgie.
>
> Unfortunately it doesn't work for me.
>
> I should've said that there are many values using this syntax, like this:
> <field>
>     <key1><![CDATA[NAME]]></key1>
>     <value><![CDATA[John Appleseed]]></value>
> </field>
> <field>
>     <key2><![CDATA[Company]]></key2>
>     <value><![CDATA[Google]]></value>
> </field>
>
>
> As you can see, there are two keys, but the very next line says *value* 
> for both of them. That is my main concern.
>
> I want *value1* for each item on the list, but its defining *key* is in 
> the line above with that CDATA formatting.
>
> Any ideas?
>
> As others have noted, expand your match pattern to reject the portions of 
the XML data you don't want to match.

Using your examples , the following regular expression will handle both 
types of match cases:

(?:\s*<key1><!\[CDATA\[NAME\]\]><\/key1>\s+<value><!\[CDATA\[(.*)\]\]><\/value>)|(?:<key1>(.*)<\/key1>)

The (?: ... ) constructs are non-capturing grouping to organize the 
alternative matching cases.

Note that you want the longest match case (i.e., the CDATA pattern) as the 
first alternative. Since that will be the first case tried for a pattern 
match and will thus correctly match on the desired CDATA pattern and not 
incorrectly use the "<key1>(.*)<\/key1>" expression for wrongly find a 
match in the CDATA text patterns.

The second alternative is the expression which matches on your "formatted 
correctly" non-CDATA formatted XML case. (This alternative is only tried 
after the first alternative fails to find a match.

Also note there are two capture fields in the regular expression. $1 
captures the name text in the first CDATA case alternative and $2 captures 
the name text in the second alternative.

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/bbd822d4-c455-4e09-8852-39dbe155d9a9%40googlegroups.com.

Reply via email to