I know regular expressions, and at last get the joke to the XKCD comic:
It does feel a little bit like I know kung fu. Regular expressions, which (essentially) search for a given pattern in a string, i.e. a set of characters (words, numbers, etc.), and then let you do something with the results. These powerful, albeit cryptic, expressions allow you to radically simplify many operations on strings.
Take, for instance, a problem presented on Coderbyte: given a string of words or letters, shift every letter over by 1 (so 'c' becomes 'd', 'z' becomes 'a'), and then capitalize any vowels excluding 'y'.
Here is a solution found sans regular expressions. Just gloss over the fine print for now and look at the size of it.
Here is a solution found using regular expressions (namely, mine).
Slight difference, right? As an added benefit, regular expressions can often let you write my like how you would talk about solving the problem:
- There's this function called 'LetterChanges,' you pass it a string.
- Give me the result of taking all the alphabetic characters in the string and doing the following with each one:
- If it's Z, change it to A
- If it's z, change it to z
- Otherwise shift the character over by one
- Replace all the vowels with …
- … an uppercase version