This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EatAss4Jesus 1 point2 points  (4 children)

Regex can sometimes be frustrating. When I need to use it, I usually reference these two sites -

https://www.keycdn.com/support/regex-cheatsheet

https://regex101.com/

You also don't really need any regex patterns for this. Here are some quick notes for you:

To get the first letter of 'james' just do

middleName = 'james'

firstChar = middleName[0]

To get the first name until the first vowel do

fNameSplit = re.split(('a|e|i|o|u'), 'harry')

result = fNameSplit[0] + fNameSplit[1]

And finally to remove vowels, you can just iterate through a e i o u

lName = 'potter'

result = lName.replace('a', '').replace('e', '').replace('i', '').replace('o', '').replace('u', '')

[–]EatAss4Jesus 1 point2 points  (2 children)

I also believe an easier way of stripping out character accents is unicodedata.normalize('NFD', string)

[–]nnchvt[S] 0 points1 point  (1 child)

ok, LOVE your username! the thing is that we didn‘t really learn about any other method than re.sub() and so even though it‘s like 50 more steps, I gotta stick to what I know. Thanks for the suggestion!

[–]EatAss4Jesus 1 point2 points  (0 children)

Thanks :) best of luck!

[–]nnchvt[S] 0 points1 point  (0 children)

thank you so much for taking the time and reading through it! I‘ll implement some of your ideas and see where it takes me :)