How to look for a letter, a sequence of letters (word) ? (Part 2 )
Knowing how to work with documents or text is a crucial skill for developers and general users alike. Using regular expressions will boost your productivity by eliminating repetitive tasks while working with documents.
In this tutorial, we are going to discover regex patterns related to looking for characters or a sequence of them. We will work with the following text :
Here is the text if you want to demo using it :
"The Bitcoin cryptocurrency, which is the first of its kind, reached 68k dollars in November 2021 before plummeting to 33k dollars today as of 10/05/2022, more than a 50% decrease. It is a big correction if we can not consider it a bubble that finally bursted. One should pay attention putting his economies in this cryptocurrency. It is so volatile that you can lose your money overnight. The Satoshi Nakamoto developed cryptocurrency registered a 42% decrease in one year and more than 20% free fall in just one month. Incredible!"
In order to search a specific character, you would do it as your usual searches. just type the character you are looking for, as shown below :
The character l is found 16 times.
2. In order to search for a list of characters, just put them one next to an other between brackets
The pattern used here for example is [aiI], which tells Sublime to look for one of the letters 'a', 'i ', or 'I'. We found 60 matches for this pattern.
2. look for a lowercase character in the english alphabet
In order to search a character in the english alphabet, use the pattern [a-z]. It tells Sublime to look for all characters between a and z, a and z are also included. Notice that uppercase letters are also included, because the Case Sensitive (bottom left) feature is not enabled.
3. look for an uppercase character in the english alphabet
AIn order to look for uppercase letters, just use the range [A-Z]. But do not forget to activate the Case Sensitive feature, otherwise Sublime will return all the characters in the text.
4. look for a lowercase character in a specific range
You can use any range you want, not just [a-z]. In this example we used the range [a-f] to search for any character alphabetically between a and f. We found 127 such letters.
5. How to combine the precedent elements to look for whole words ?
You can combine multiple ranges in one pair of brackets. In this example we can search for a combination for either lowercase or uppercase letters. We used the pattern [a-zA-Z]* which means 'look for a character from a to z or A to Z repeated zero or many times'