Match Accented Letters with Regular Expressions
Regular expressions are used for a variety of tasks but the one I see most often is input validation. Names, dates, numbers...we tend to use regular expressions for everything, even when we probably shouldn't.
The most common syntax for checking alphabetic characters is A-z
but what if the string contains accented characters? Characters like ğ
and Ö
will make the regex fail. That's where we need to use Unicode property escapes to check for a broader letter format!
Let's look at how we can use \p{Letter}
and the Unicode flag (u
) to match both standard and accented characters:
// Single word
"Özil".match(/[\p{Letter}]+/gu)
// Word with spaces
"Oğuzhan Özyakup".match(/[\p{Letter}\s]+/gu);
Using regular expressions to validate strings, especially names, is much more difficult than A-z+
. Names and other strings can be very diverse -- let's not insult users by making them provide non-accented letters just to pass validation!
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?
dwProgressBar was a huge hit when it debuted. For those of you who didn't catch my first post, dwProgressBar is a MooTools 1.2-based progress bar which allows for as much flexibility as possible. Every piece of dwProgressBar can be controlled by CSS...
One of the sweet effects made easy by JavaScript frameworks like MooTools and jQuery is animation. I ran across this great jQuery tutorial that walks you through animating a background image of a page. Here's a quick MooTools code snippet that...