On 05/22/2021, at 19:22, severdia <[email protected] <mailto:[email protected]>> wrote: > Yes, you're right. I got it working, but for future reference here's what I > was trying to do...I have many of these elements: > > <work>Macbeth<loc>5.1</loc><loc2>5.1.64</loc2></work> > > Both <loc> and <loc2> contain act/scene/line number info and either one other > the other is incomplete (the one with two numbers) and I want to keep the one > that's complete (with three numbers). My objective was to delete either <loc> > or <loc2> if it had only two numbers in it.
Hey Ron, Explaining your actual task is quite helpful – but I always want to see examples of the start condition and the desired outcome in black and white. 😎 Like so: Data Sample 01: <work>Macbeth<loc>5.1</loc><loc2>5.1.64</loc2></work> Desired Outcome 01: <work>Macbeth<loc2>5.1.64</loc2></work> You wouldn't believe how often people leave out or otherwise mangle instructions. The "A picture is worth a thousand words." rule is highly relevant with this sort of task. Here's what I would do: Find: <loc(\d?)>\d+\.\d+</loc\1> Replace with nothing. With <loc(\d?)> I'm finding a digit that may ore may not exist and I'm using that capture in the closing tag </loc\1>. This covers any loc tag from 0-9. This is a trifle simpler and more direct (if there are only <loc> and <loc2> tags). <loc2?>\d+\.\d+</loc2?> While we're on the topic of data massage with regex, let me recommend this site to you: https://regex101.com/r/WtIAmE/3 <https://regex101.com/r/WtIAmE/3> (This link contains your example problem.) When I'm working on complex regular expressions I always start with BBEdit, but if I have substantial problems I have some regex visualizer apps (RegExRx <https://apps.apple.com/us/app/regexrx/id498370702?mt=12> in particular) and RegEx101.com <http://regex101.com/> to fall back on. I can't use BBEdit 13's new Pattern Playground on my main Mac, because Sierra isn't supported. One reason to look forward to getting new hardware... -- Best Regards, Chris -- This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "[email protected]" 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/7FB473E5-2467-4D8D-BE44-2351216E4B49%40gmail.com.
