
learning python, join me if you'd like
#21
Posted 25 January 2023 - 04:16 AM
#22
Posted 25 January 2023 - 08:40 AM
Match:
banana
absinthe
cabana
baccarat
No match:
ankle
browser
elbow
shanty
?
Also match:
Brand
Drawback
#23
Posted 25 January 2023 - 08:44 AM
I think you get what I'm going for, yes.
I have the words in a list object like this:
word_list = ['apple', 'guy', 'stuck', 'blah']
eta: I picked those words at random, only blah meets the criteria
Edited by postSingularityHumanoid, 25 January 2023 - 08:47 AM.
#24
Posted 25 January 2023 - 08:49 AM
/.*a.*b.*|.*b.*a.*/
.* matches 0 or more of any character (basically a wildcard)
So this translates as
Anything followed by an a, followed by anything, followed by a b, followed by anything. OR anything followed by b, followed by anything, followed by a, followed by anything.
And note that in this context "anything" really means "anything or nothing".
Regexpal.com is your friend btw
Edited by Stains_not_here_man, 25 January 2023 - 08:48 AM.
#25
Posted 25 January 2023 - 08:54 AM
So for that particular example, again this isn't python specific but the regex itself would be
/.*a.*b.*|.*b.*a.*/
.* matches 0 or more of any character (basically a wildcard)
So this translates as
Anything followed by an a, followed by anything, followed by a b, followed by anything. OR anything followed by b, followed by anything, followed by a, followed by anything.
And note that in this context "anything" really means "anything or nothing".
Regexpal.com is your friend btw
oh, I didn't know these were sort of universal. so the * always modifies the thing that precedes it, right? and it basically means, "any number of that thing" and since period is "anything" that's how you arrived there?
#26
Posted 25 January 2023 - 09:31 AM
#27
Posted 25 January 2023 - 12:40 PM
Yep!
okay, cool. thanks!
#28
Posted 26 January 2023 - 06:11 AM
damn, so something that complicates this a little is the number of letters is variable. could be 1, 2, 3, etc.
you kind of hard coded it for 2 letters but I guess for 3 I'd need 6 small REs divided up with "or"s? I haven't thought about it too long yet though so I may not have right....
#29
Posted 26 January 2023 - 06:13 AM
#30
Posted 26 January 2023 - 06:19 AM
Keep in mind that regex itself is mostly useful for things that are "patterns". In some cases a for loop or a series of them may be more appropriate depending on the variability of the thing you're looking at.
yeah, I was just trying to exercise my RE skills.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users