Interaction with regular expression is not easy. Nobody is really happy to analyze ^(19|20)\d\d[- /.](0[1-9]|1)[- /.](0[1-9]|[0-9]|3)$ and try to find out what this really means.
But still, regular expressions are a very powerful tool and it’s recommended to understand the way they work, even if you are not an expert in this field.
This article is a useful introduction to the world of regular expressions. If you meet them while performing software testing, you will feel confident and technically free.
Regular expressions are simply a consequence of certain symbols that define a template for seeking something.They can be used for editing the lines of software code and also, for testing the correspondence between a phone number, date, postal code, and an established template.
You should also know that they are easier to operate when you have good testing software in your hands. In our case, it’s Regex software.
Further, we’ll analyze 10 most popular symbols of regular expressions that can be met every day while performing software testing. And it’s Regex that will help us to interpret this.
A special symbol “caret” indicates that a user wishes to find matches with the beginning of a certain word.
For example, if a user uses a template ^foot, he/she will get matches with such words as ^football, ^footstep.
This dollar symbol means that a user wishes to find a match with the end of a certain word.
The pattern that ends with ball$, can find the word football but can’t find the word balloon since this word doesn’t begin with the part ball.
A special symbol of a full stop indicates a match with a special symbol. It can be used when one of the special symbols varies.
The pattern foo.ball can find football and also foosball.
A special symbol of an asterisk indicates that a special symbol can/should match once or several times.
In our pattern fo*tball, a letter “O” can coincide one or several times.
This pattern can find football, fotball and foooootball.
Backslash and d indicate searching for a match with any suggested number.
Our pattern football\d can easily match with football1, football2 and so on but it won’t match with football or football!
Double brackets are responsible for grouping a pattern, in the same way as mathematical expressions.
Let’s imagine that we would like to find December or November but not January. If we have no possibility to use pattern “ember”, it will simply match with all current months. But we can operate (Dec-Nov)ember — using brackets with a horizontal line means that the month we are searching for can begin with Dec or Nov and should end with ember.
The topic of regular expressions is a very interesting field that beckons us but can make us lost in it.
Junior specialists should “play” with Regex software to not only practice but also, learn the basics of working with regular expressions.