Grep for everything between two tags?

502 views
Skip to first unread message

Jerry Nilson

unread,
Aug 13, 2018, 11:35:03 AM8/13/18
to BBEdit Talk
Hi,

Cannot figure out (new to this) how to write a grep search to match:
        <description><![CDATA[data1: 2820<br>data2 (m): <br>data3: word word<br>data4: XX-7-3056<br>data5:<br>data1: 2820<br>data2 (m): <br>data3: word word<br>data4: XX-7-3056<br>data5: ]]></description>

Where I want to substitute all similar lines with:
        <description></description>

Thought I could write:
        <description>.*</description>
or possibly with a ? after, but seems I may need more escape characters here because some of the characters to be deleted are also grep characters? Tried witch escapes too, but cannot get it quite right apparently ... .

All the best,
Jerry

Sam Hathaway

unread,
Aug 13, 2018, 11:46:36 AM8/13/18
to BBEdit Talk

<description>.*?</description> worked for me with your sample line.
-sam

--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.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+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.

Jerry Nilson

unread,
Aug 13, 2018, 11:56:35 AM8/13/18
to BBEdit Talk
You are right! 😃 I bloody well tried exactly that too, but maybe I had not selected the whole row when applying to "selected text" only (as I did not see the full row on my computer ...). Now it of course worked right away! Tried to fix a kmz file exported from a Google map, that mishandles the code when exporting if one has added extra columns of data (now found out I could have deleted the columns on the map before exporting .... oh well, but need this anyway as they will add this column back despite that they should not (should not do that with info one has not entered in that column as it is, but ...)).

Thanks – need to learn more Grep ... !
Jerry

Patrick Woolsey

unread,
Aug 13, 2018, 1:01:21 PM8/13/18
to bbe...@googlegroups.com
One potential catch here is that by default the . metacharacter
doesn't match past hard line breaks, so if the desired data
spans one or more lines, a pattern like this:

Find: <description>.*</description>

won't work.

You can however modify this behavior by pre-pending the pattern
modifier (?s), and then for insurance adding a ? to prevent the
match from being 'greedy', making a search pattern:

Find: <description>(?s).*?</description>

so please give that a try. :-)


Regards,



Patrick Woolsey

==

Bare Bones Software, Inc. <http://www.barebones.com/>


Jerry Nilson

unread,
Aug 14, 2018, 9:02:07 AM8/14/18
to BBEdit Talk
Thanks!
Reply all
Reply to author
Forward
0 new messages