Page 1 of 1

Regex help for %%r:STRING%%

PostPosted: Sat Nov 21, 2020 9:40 am
by mundmc
Yes i am being lazy and yes i need to practice regex, but if anybody can do this in their sleep, help is appreciated!

Sample input= “words and stuff %%r:livingroom%% words and stuff”

I would like a python regex snippet to return “livingroom” in this case, or some other value to indicate no match.

Yes, this the first part of my kludgy way of indicating if an Indigo Device is assigned to a room, using the “Notes” field of the Device.

Edit: Never mind, i got something to work, but am certainly open to better ideas:

Code: Select all

import re

text = "words words %%r:den%% words"

room = re.search('%%r:(.*?)%%', text)
print(room.group(1))



Edit 2:

Silly me, i realized this could easily be achieved with
Code: Select all
if “%%r:den%%” in text:
     print(“den”)