Regex Help!
-
The code I put above returns the string in between <tags></tags> as in your original example (is that not working on your system?). Give me more details about what you want to do.
-
what do you want to modify? There's a user preset handler preload callback which lets you process the preset data as JSON before it's loaded, so maybe you don't have to resort to Regexing an XML like it's 1982...
-
@Christoph-Hart He wants to make a custom interface for managing preset tags. See other thread - https://forum.hise.audio/topic/8142/tagging-presets/
-
@Christoph-Hart @d-healey Yeah, im using a custom browser (preset browser tags wont work AFAIK) and I'm looking for a way to add tags to the preset file, some suggested putting it on the file name/making an internal database of preset tags, but for my use case, (preset sharing plays a big role), I'm looking for a way to add presets to the xml file itself. @d-healey suggested using the load as string and write as string functions to modify the xml itself so I'm thinking of adding a structure like this to the xml:
<?xml version="1.0" encoding="UTF-8"?> <Preset Version="1.0.0"> <Content Processor="Interface"> <Control type="ScriptControl" id="amazingId" value="0.0"/> </Content> <Tags> <Tag>Synth</Tag> <Tag>Pad</Tag> <Tag>Pluck</Tag> </Tags> <MidiAutomation/> <MPEData Enabled="0"/> </Preset>
and be able to read the tags as strings and put them in arrays in hise. Hence my question of using regex to just get this part out of the mess above:
<Tag>Synth</Tag> <Tag>Pad</Tag> <Tag>Pluck</Tag>
The regex @d-healey posted does weird things on my system and creates an undefined file, i also tried to use the split() function like this: split("<Tags>") it splits the whole xml string by
<
's (even when using<
as a unicode character thinking<
itself may be causing issues) -
@Casmat I wouldn't put each tag within <tag></tag>. I'd just use a comma separated list, then you can easily put it into an array.
-
@d-healey ahh. that makes life easier! any idea still on how to get the <Tags> identifiable in hisecript? heres what I have in my code:
inline function taggingView() { reg preset = filePreset.loadAsString(); Console.print(preset); if(preset.contains("\u003C" + "Tags" + "\u003E")) { reg result = Engine.getRegexMatches(preset, "<Tags>(.*?)<\/Tags>")[1]; Console.print(result); } };
but result comes out as undefined.. preset is the preset file.
-
@Casmat Use
local
within inline functions, notreg
.My guess is it doesn't like the new line characters.
Try
local matches = Engine.getRegexMatches(s.replace("\n"), "<Tags>(.*?)<\/Tags>");
-
@d-healey used reg to look at the script watch table, is there a way to see local variables in that table? And that was a very good guess! Thanks :)
-
-
@d-healey ooh, never looked there! Thanks!