December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 39 | Global and Case-Insensitive Matching with the g and i Flags |
Suppose your task is creating a U.S. version of an existing company website. You need to search the content of web pages, find instances of the word “tyre,” including its plural form “tyres,” and replace each with its American spelling “tire.” The search must ignore the letter case, so it matches “Tyre” at the beginning of sentences as well.
Another requirement is to find all possible matches in the string. So, rather than stopping the search as soon as a match is found, the engine must continue looking for more matches in the rest of the string. Doing all these manually takes a lot of time. Fortunately, regex flags are here to save the day.
One More Time? | |
|---|---|
|
You have already ... | |
Read now
Unlock full access