**Regular Expression : Python**

in technology •  6 years ago 

Well to people who are not into tech fields this topic might look like a english syntax , But you might be knowing it in other way. For ex: when you type incorrect word in google and it searches and shows you the result for correct word or when you say to Google Assistant , Microsoft's Cortana or Apple Siri they understand you beacuse they construct words and particular action for those through regular expression.
Today I'll tell you about the three basic methods of Regular expression which is very much important for a beginner who wants to pursue career in Data Science, Deep Learning, Machine Learning etc.

To start working with regular expression you need to install Regular expression module for python through pip or anaconda seems the best way(for me atleast p:). Once you have installed regular expression package you can import it and get start working with it.
import re This way you import it.
Three basic methods which is must for any beginner to begin with are
1: re.search()
2: re.match()
3: re.findall()
With re.search() you can search for a particular pattern in the given input pattern, suppose you need to find whether pattern 'abc' is present in the given input which is 'bchdjddjdjhfhfbfjsssjjabcjdshshs' . Now as you can see that the pattern is present but this is just a test case , real world situation consist of million of data which you cannot verify for pattern and simple if\else case can work in this case but wont work in big size data as it'll consume huge amount of time.

So search for this pattern we need to perform following operation
re.search('pattern to be search','input from which the pattern is to be searched)
This search method searches the entire input pattern and if there are two pattern present in the input pattern then it just shows the first pattern.

Now moving on to next method re.match(), what it does is it matches the pattern from the beginning of the input pattern. If it does not find the pattern to be searched in the beginning then it returns none or nothing.syntax for it will be
re.match('pattern to be searched', 'input from which pattern is to be searched')

For the last method re.findall() ,It's same as re.search() method but every aspect but takes lead in finding all the matching pattern in the given input pattern and not just the first one.
re.findall('pattern to be searched','input from which pattern is to be searched')

I hope this makes it clear for the noobs out there as I'm one of you.
Happy Coding!!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Nice post! I deal with regexps almost every day! :D

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Congratulations @anoopshrma! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!