While learning multiple ways to create a Pig Latinizer, I struggled to understand how a complex regex (regular expression) works its magic inside a .split method.
More specifically, I was amazed yet perplexed by a simple line of code (via this amazing programmer):
“forest”.split(/([aeiou].*)/)

=> [“f”, “orest”]

The goal of this split method is to divide a word into an array of two strings, with the first vowel of the word as a delimiter. As illustrated above, the first string contains all character(s) before the first vowel, and the second string has all characters after the first vowel (including the vowel itself).
To demystify the complexity of this split/regex combo, I decided to, uh, “split” up the regex — one regular expression at a time.

#regex #ruby-on-rails #programming #ruby #coding

Breaking Down a Complex RegEx
2.00 GEEK