Search pattern works in Notepad++ , but not in BBEdit

101 views
Skip to first unread message

Samir Vasaya

unread,
Nov 29, 2023, 3:22:15 PM11/29/23
to BBEdit Talk
Hello.
I have a .xlm file with below sample contents.

     <ALLINVENTORYENTRIES.LIST>
      <STOCKITEMNAME>MYNoodles_5Rs_0720</STOCKITEMNAME>
      <HSNITEMSOURCE></HSNITEMSOURCE>
      <BATCHALLOCATIONS.LIST>
       <GODOWNNAME>Main Location</GODOWNNAME>
      </BATCHALLOCATIONS.LIST>
      <ACCOUNTINGALLOCATIONS.LIST>
       <OLDAUDITENTRYIDS.LIST TYPE="Number">
        <OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
       </OLDAUDITENTRYIDS.LIST>
       <LEDGERNAME>Sales @ 12% GST</LEDGERNAME>
     </ALLINVENTORYENTRIES.LIST>
     <ALLINVENTORYENTRIES.LIST>
      <STOCKITEMNAME>PF 05 CNS0720</STOCKITEMNAME>
      <HSNITEMSOURCE></HSNITEMSOURCE>
      <BATCHALLOCATIONS.LIST>
       <GODOWNNAME>Main Location</GODOWNNAME>
      </BATCHALLOCATIONS.LIST>
      <ACCOUNTINGALLOCATIONS.LIST>
       <OLDAUDITENTRYIDS.LIST TYPE="Number">
        <OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
       </OLDAUDITENTRYIDS.LIST>
       <LEDGERNAME>Sales @ 12% GST</LEDGERNAME>
     </ALLINVENTORYENTRIES.LIST>


I do a Search and Replace using Grep in BBEdit with

Search pattern:

(?s)(?=<ALLINVENTORYENTRIES\.LIST>(?|(<STOCKITEMNAME>)|.)*?(?(1)(?=([^<]+)<\/STOCKITEMNAME>)|<\/ALLINVENTORYENTRIES\.LIST>))(?(2)(?=<ALLINVENTORYENTRIES\.LIST>(?|(<HSNITEMSOURCE>)|.)*?(?(3)(?=(\2))?|<\/ALLINVENTORYENTRIES\.LIST>))(?(3)(?(4)^\b$|<ALLINVENTORYENTRIES\.LIST>.*?(?=<HSNITEMSOURCE>)<HSNITEMSOURCE>\K)|^\b$)|^\b$)



Replace pattern:

\2


Im not getting the desired results, Pattern playground hi lights sub patterns 1, 2 and 3 Correctly, But the Replacement text: for \2 shows the captured text incorrectly.


Am I m doing something wrong. I have gone through BBEdit manual, but couldn’t find anything that helped.

I ran the same pattern in Notepad++ and it works flawlessly.

jj

unread,
Nov 30, 2023, 3:49:55 AM11/30/23
to BBEdit Talk
Hi Samir,

A few remarks.

1. The <ACCOUNTINGALLOCATIONS.LIST> tag is not correctly closed in you XML example.

2. I can reproduce the issue you mention and effectively BBEdit is returning garbage in the 'Replacement Text' field of the playground even if it shows the correct \2 in the 'Capture Groups' table.

3. If you use your pattern/replacement in a find/replace over you sample text and extract the results in a new document,  you can clearly see with 'File > Hex Dump Front Document' that the replacements are pointing to random memory.

4. There is apparently a bug somewhere.

5. You should send an email to sup...@barebones.com with your issue to open a case.

HTH,

Jean Jourdain


Samir Vasaya

unread,
Dec 1, 2023, 1:54:43 PM12/1/23
to BBEdit Talk
Hi Jean,
thanks for confirming my observations.
yes the tag you mentioned is not closed.
I have mailed to barebones, and I found  them to be very supportive and they have promised a fix, 
may be not soon , but they are working to solve the issue.

Thanks.

wbrisett

unread,
Dec 2, 2023, 10:08:46 AM12/2/23
to BBEdit Talk
I will point out that parsing XML with regex isn't really how you should do things... (but then I work with XML every day and I do understand there are some needs that XSLT and XPATH won't work for with folks). 
Reply all
Reply to author
Forward
0 new messages