Regex help for %%r:STRING%%

Posted on
Sat Nov 21, 2020 9:40 am
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Regex help for %%r:STRING%%

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”)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest