0

Long story short, I'm trying to "clean up" a script file from a drawing program for playback. The program (ArtRage for iPad) will record all strokes to an XML script file that. You can then export this file and play back the entire drawing process in the iPad or desktop version of the application. I want to clean out all of the "undo" operations.

The drawing "step" looks like this:

<StrokeEvent>
<StrokeHeader>
    <EventPt>   Wait: 0.428s    Loc: (806.416, 439.849) Pr: 1   Ti: 1   Ro: 0   Fw: 1   Bt: 0   Rv: NO  Iv: NO  </EventPt>
    <Recorded>  Yes </Recorded>
</StrokeHeader>
Wait: 0.000s    Loc: (805.622, 437.537) Pr: 1   Ti: 1   Ro: 0   Fw: 1   Bt: 0   Rv: NO  Iv: NO
</StrokeEvent>

I've shortened it up a bit, but the entire thing is contained in opening and closing tags.

The undo operation looks like this:

Wait: 0.661s    EvType: Command CommandID: Undo

and it comes right after the step you are undoing.

So ... I'd like to search for just those instances of the complete tag that have an undo operation immediately after it, and then delete both the complete tag and undo line.

I think regex would be a good way to do this, but I don't know it very well. I'm going through a regex class online, but it will just take me a bit to ramp up and this particular solution could come in handy sooner. I've been able to select complete tags, but I can't select just those that have an undo statement following them. I tried using look forward but that selects ALL preceding tags.

Here's the closest I was able to get (excuse the sloppy newbie code):

(<StrokeEvent>[\s\S]+?</StrokeEvent>)\nWait:.*Undo

I thought the "?" after the "+" would enable the lazy option and stop at the first occurrence of , but I may be understanding it wrong.

Anyway, thanks for any tips you can give me!

Shawn
  • 9
  • 1
  • Replace `[\s\S]+?` with `(?:(?!)[\s\S])*?` – Wiktor Stribiżew Jun 16 '17 at 18:44
  • Even though `[\S\s]+?` is un-greedy, this is one of those cases where it becomes greedy to get to the `Wait:` literal. It's going to find the first event, and go all the way to the last event where it finds a followning _Wait_ no matter what is in between. –  Jun 16 '17 at 18:51
  • Your description with "_immediately after_" and "_following them_" (etc) does point to [lookahead (in perlretut)](http://perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind). But they are a little tricky and one needs to play around with them to get it. They do come very handy sometimes. – zdim Jun 16 '17 at 18:52
  • Fwiw, should that sample be `Wait: 0.000s Loc: (805.622, 437.537) Pr: 1 Ti: 1 Ro: 0 Fw: 1 Bt: 0 Rv: NO Iv: NO ` or ` Wait: 0.000s Loc: (805.622, 437.537) Pr: 1 Ti: 1 Ro: 0 Fw: 1 Bt: 0 Rv: NO Iv: NO` ? –  Jun 16 '17 at 19:01
  • 1
    So your sample XML doesn't contain any examples of what you want to remove. Is that right? – Borodin Jun 16 '17 at 21:44
  • @sin What makes it a bit confusing is that there can be "Wait" statements inside of the tags too. I'm just targeting the "Wait" commands that come right after a tag and are at the same "level" and end in "Undo". Hopefully that makes sense. – Shawn Jun 19 '17 at 13:51
  • @WiktorStribiżew That did it! Thanks very much. – Shawn Jun 19 '17 at 13:52
  • @Shawn You are welcome. – Wiktor Stribiżew Jun 19 '17 at 13:53
  • @Borodin I actually want to eventually delete what I'm selecting. So, in the actual XML file, I want to select every instance of tag immediately followed by a "Wait" command that ends in "Undo", and then select that "Wait" command as well. I figured my first step is just being able to select them. – Shawn Jun 19 '17 at 13:54

0 Answers0