Skip to content
Advertisement

Regex XML Selection Extract Element

I am trying make a regex selection starting from BYPASS 0 0 0 up to and including the section where it says WAK 0 0 Here is what I have (?s)(?=BYPASS).*?(WAK....) I think my syntax for python use is incorrect also here is how I use it in python script re.split(r'(?s)(?=BYPASS).*?(WAK....)', r) I believe this is causing the problem for me (?s) resulting with incorrect regex selections.

<REAPER_PROJECT 0.1 "6.66/win64" 1661879469
  <NOTES 0 2
  >
  RIPPLE 0
  GROUPOVERRIDE 0 0 0
  AUTOXFADE 129
  ENVATTACH 3
  POOLEDENVATTACH 0
  MIXERUIFLAGS 11 48
  PEAKGAIN 1
  FEEDBACK 0
  PANLAW 1
  PROJOFFS 0 0 0
  MAXPROJLEN 0 600
  GRID 3199 8 1 8 1 0 0 0
  TIMEMODE 1 5 -1 30 0 0 -1
  VIDEO_CONFIG 0 0 256
  PANMODE 3
  CURSOR 0
  ZOOM 100 0 0
  VZOOMEX 6 0
  USE_REC_CFG 0
  RECMODE 1
  SMPTESYNC 0 30 100 40 1000 300 0 0 1 0 0
  LOOP 0
  LOOPGRAN 0 4
  RECORD_PATH "" ""
  <RECORD_CFG
    ZXZhdxgAAA==
  >
  <APPLYFX_CFG
  >
  RENDER_FILE ""
  RENDER_PATTERN mask
  RENDER_FMT 0 2 44100
  RENDER_1X 0
  RENDER_RANGE 1 0 0 16 1000
  RENDER_RESAMPLE 3 0 1
  RENDER_ADDTOPROJ 0
  RENDER_STEMS 2048
  RENDER_DITHER 0
  TIMELOCKMODE 1
  TEMPOENVLOCKMODE 1
  ITEMMIX 1
  DEFPITCHMODE 589824 0
  TAKELANE 1
  SAMPLERATE 44100 0 0
  <RENDER_CFG
    ZXZhdyAAAA==
  >
  LOCK 1
  <METRONOME 6 2
    VOL 0.25 0.125
    FREQ 800 1600 1
    BEATLEN 4
    SAMPLES "" ""
    PATTERN 2863311530 2863311529
    MULT 1
  >
  GLOBAL_AUTO -1
  TEMPO 120 4 4
  PLAYRATE 1 0 0.25 4
  SELECTION 0 0
  SELECTION2 0 0
  MASTERAUTOMODE 0
  MASTERTRACKHEIGHT 0 0
  MASTERPEAKCOL 16576
  MASTERMUTESOLO 0
  MASTERTRACKVIEW 0 0.6667 0.5 0.5 -1 -1 -1 0 0 0 -1 -1 0
  MASTERHWOUT 0 0 1 0 0 0 0 -1
  MASTER_NCH 2 2
  MASTER_VOLUME 1 0 -1 -1 1
  MASTER_PANMODE 3
  MASTER_FX 1
  MASTER_SEL 0
  <MASTERPLAYSPEEDENV
    EGUID {07BFCFC9-6DA0-4D9C-8821-7D1555F3F3F8}
    ACT 0 -1
    VIS 0 1 1
    LANEHEIGHT 0 0
    ARM 0
    DEFSHAPE 0 -1 -1
  >
  <TEMPOENVEX
    EGUID {9059CD91-68BB-42A7-8E08-BCDDCB3AC50B}
    ACT 0 -1
    VIS 1 0 1
    LANEHEIGHT 0 0
    ARM 0
    DEFSHAPE 1 -1 -1
  >
  <PROJBAY
  >
  <TRACK {7233B3F7-03A2-4203-B516-704EFF3393E3}
    NAME dac
    PEAKCOL 16576
    BEAT -1
    AUTOMODE 0
    VOLPAN 1 0 -1 -1 1
    MUTESOLO 0 0 0
    IPHASE 0
    PLAYOFFS 0 1
    ISBUS 0 0
    BUSCOMP 0 0 0 0 0
    SHOWINMIX 1 0.6667 0.5 1 0.5 -1 -1 -1
    SEL 0
    REC 0 0 1 0 0 0 0 0
    VU 2
    TRACKHEIGHT 138 0 0 0 0 0
    INQ 0 0 0 0.5 100 0 0 100
    NCHAN 4
    FX 1
    TRACKID {7233B3F7-03A2-4203-B516-704EFF3393E3}
    PERF 0
    MIDIOUT -1
    MAINSEND 1 0
    <FXCHAIN
      WNDRECT 330 364 511 642
      SHOW 0
      LASTSEL 2
      DOCKED 0
      BYPASS 0 0 0
      <VST "VST: FreeG (Sonalksis)" "Sonalksis FreeG Stereo (64 bit).dll" 0 "" 1181894483<56535446724753667265656700000000> ""
        U0dyRu5e7f4CAAAAAQAAAAAAAAACAAAAAAAAAAIAAAABAAAAAAAAAAIAAAAAAAAAPAAAAAEAAAAAABAA
        aH5iPgAAAD8AAAAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAA
        AE5vbmUAEAAAAA==
      >
      PRESETNAME None
      FLOATPOS 0 0 0 0
      FXID {B7036F0D-9C41-461A-B1F6-CEB9D441E7EF}
      WAK 0 0
      BYPASS 0 0 0
      <VST "VST: FreeG (Sonalksis)" "Sonalksis FreeG Stereo (64 bit).dll" 0 "" 1181894483<56535446724753667265656700000000> ""
        U0dyRu5e7f4CAAAAAQAAAAAAAAACAAAAAAAAAAIAAAABAAAAAAAAAAIAAAAAAAAAPAAAAAEAAAAAABAA
        uDDmPQAAAD8AAAAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAA
        AE5vbmUAEAAAAA==
      >
      PRESETNAME None
      FLOATPOS 0 0 0 0
      FXID {9EEDFB75-3908-406D-BB87-69B4E868EDEA}
      WAK 0 0
      BYPASS 0 0 0
      <VST "VST: FreeG (Sonalksis)" "Sonalksis FreeG Stereo (64 bit).dll" 0 "" 1181894483<56535446724753667265656700000000> ""
        U0dyRu5e7f4CAAAAAQAAAAAAAAACAAAAAAAAAAIAAAABAAAAAAAAAAIAAAAAAAAAPAAAAAEAAAAAABAA
        I8XFPgAAAD8AAAAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAA
        AE5vbmUAEAAAAA==
      >
      PRESETNAME None
      FLOATPOS 0 0 0 0
      FXID {B0417D0E-CEA3-4E1F-9BF3-7D4DCE72AC39}
      WAK 0 0
    >
    <ITEM
      POSITION 0
      SNAPOFFS 0
      LENGTH 14.22222222222222
      LOOP 1
      ALLTAKES 0
      FADEIN 1 0.01 0 1 0 0 0
      FADEOUT 1 0.01 0 1 0 0 0
      MUTE 0 0
      SEL 1
      IGUID {D7A853A4-5113-4456-A452-7369A41CBB08}
      IID 1
      NAME dac.wav
      VOLPAN 1 0 1 -1
      SOFFS 0
      PLAYRATE 1 1 0 -1 0 0.0025
      CHANMODE 0
      GUID {723895C2-2164-4743-9EAD-77CD9086FD1A}
      <SOURCE WAVE
        FILE "dac.wav"
      >
    >
  >
>

Advertisement

Answer

I am not sure what you mean by “regex selection”. The text you want can be matched with the regex (?s)(BYPASS 0 0 0.*?WAK 0 0) where:

"(?s)" signifies that the '.' char can match any character, including a newline
"("    begin capturing group
"BYPASS 0 0 0" the literal characters
".*?"  zero or more times any char, including newlines
"WAK 0 0" the literal characters
")"    end capturing group

You use re.split(regex, txt) that splits the string txt at the points specified by regex and returns an array of the new strings.

e.g.

x = re.split("a","bananas")
# x = ['b','n','n',s']

x = re.split("(a)", "bananas")
# x = ['b','a','n','a','n','a','s']

If what you want is to get the parts that start from BYPASS 0 0 0 and end with WAK 0 0, you can use re.findall(regex, txt) that returns all the parts from txt that match regex.

e.g.

x = re.findall(r"bw*s", "bananas, beers and bootstrap 5")
# x = ['bananas', 'beers', 'boots']

Or in your case

x = re.findall("(?s)(BYPASS 0 0 0.*?WAK 0 0)", txt)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement