Reputation: 6517
I have the following problem: I'm trying to check whether some text consists only of a number of repetitions of some pattern. I.e I have a 1000 lines text and want to check if it consists only of
asd
123
I tried matching not the pattern, but (pattern)+
hoping that it will match whatever there is to match but it was to no avail. My other idea was to split the string with the text upon the regex, but it didn't work either. I'm writing this using python re module if it matters. Thanks!
Upvotes: 2
Views: 109
Reputation: 12375
I haven't tried this in Python, but the regex for what you are asking for would be the following:
.asd$
.123$
Try reading through the following webpage and see if it gives you a better understanding:
http://www.regular-expressions.info/reference.html
Hope this helps!
Upvotes: 1
Reputation: 33908
Try matching the string with ^(?:asd|123)+$
, if it matches, then it only contains combinations of asd
or 123
(at least one).
Upvotes: 1