Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the regular expression for a Spanish word?

Tags:

.net

regex

word

Regular expression languages use \B to include A..Z, a..z, 0..9, and _, and \b is defined as a word boundary.

How can I write a regular expression that matches all valid Spanish words, including characters such as: á, í, ó, é, ñ, etc.?

I'm using .NET.

like image 728
Dan Vanderboom Avatar asked May 22 '09 04:05

Dan Vanderboom


2 Answers

Use a Spanish locale and make your regex locale-sensitive.

like image 158
Dave Avatar answered Sep 17 '22 17:09

Dave


Your regex system should have something equivalent to Python's re.L (aka re.LOCALE) to make a regex locale-dependent, so that what's a word-character and what isn't changes with locale, as do "word boundaries" etc. Are you instead asking for a way to compensate for some given regex system not supporting locale, trying to force the issue anyway...?

like image 34
Alex Martelli Avatar answered Sep 20 '22 17:09

Alex Martelli