I have been wanting to learn regex. Not just because it reminds me of q a bit but because it’s actually very useful and can be used within numerous languages including python. In case you don’t know, regex stands for regular expression. A regex is “a sequence of characters that define a search pattern.” Most popular use case is to search strings for a pattern.
I was looking at videos from this year’s PyCon and stumbled up on a video of Trey Hunner conducting regex workshop at PyCon 2016. If you are looking to learn regex, I encourage you to watch the video. You can also find most of the stuff mentioned in the video on this website.
After I watched the video, I did some practice on my own which I wanted to share here.
This implies that the Kamagra viagra cheap no prescription jelly can provide you with a better result and happy sexual life. see these guys sildenafil 100mg uk Male impotency has been a common issue among the males has been reported as a significant factor for their broken relationship. viagra 50mg price Still, the ED patients can buy this drug by using sildenafil citrate as a key ingredient. Thereby you can’t perform well in the lovemaking activities. find out this order levitra online
# Import the regex module
import re
# Define our sentence
sentence = "I am a 26 years old software developer and I used to work on Wall Street (10005)."
Get the first digit from the sentence
re.search(r'\d', sentence).group()
Get the first non-digit from the sentence
re.search(r'\D', sentence).group()
Search for a substring in the sentence
re.search(r'years', sentence).group()
re.search(r'heart', sentence) # Doesn't return anything since our sentence doesn't have 'heart'
Get the first character from the sentence
re.search(r'\w', sentence).group()
Get the first word with 3 or more characters from the sentence
re.search(r'\w{3,}', sentence).group()
Get the first word with 3 or less characters from the sentence
re.search(r'\w{,3}', sentence).group()
Get the zip code from the sentence (any 5 consecutive digits)
re.search(r'\d{5}', sentence).group() # Get 5 consecutive digits
Search for 'wall' in the sentence
re.search(r'wall', sentence) # doesn't return anything, need to ignore case
re.search(r'wall', sentence, re.IGNORECASE).group()
Split the sentence at 'and'
re.split(r'and', sentence)