![]() |
matching a repeating string - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: matching a repeating string (/thread-37541.html) |
matching a repeating string - Skaperen - Jun-23-2022 i have a single character (such as ".") in variable foo and another variable bar with a one or more repeat of a single character (such as "..."). i would like to know if foo matches all the repeats of bar. empty strings should never be considered to match. is this the best way to do that? if foo and bar and foo*len(bar) == bar: ... RE: matching a repeating string - BashBedlam - Jun-23-2022 If bar will always be a single character repeated an number of times thenif foo in bar : would be the most straight forward test to see ifbar isfoo repeated.
RE: matching a repeating string - Skaperen - Jun-23-2022 no, bar could be some other value that may or may not be a repeating character. it may have an instance of foo within but if there is anything else in bar then i want a false result. bar="BashBedlam" and foo="B" needs to be false, but bar="BB" needs to be true when foo="B" .
|