# UTF8 Regex in 1.2.x

**URL:** <https://www.ruby-forum.com/t/utf8-regex-in-1-2-x/121861>\
**Category:** Rails\
**Created:** [December 2, 2007, 1:56am UTC](https://www.ruby-forum.com/t/utf8-regex-in-1-2-x/121861 "2007-12-02T01:56:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [December 2, 2007, 1:56am UTC](https://www.ruby-forum.com/t/utf8-regex-in-1-2-x/121861/1 "2007-12-02T01:56:29Z")

</div>

So, I’ve been pounding the web for info on UTF8 in Ruby and Rails the  
past couple days to concoct some validations that allow UTF8  
characters. I have discovered that with the patches applied in Rails  
1.2, I can get a little further by doing the following declaring  
$KCODE = ‘UTF8’ in environment.rb and by adding /u to regex expressions.

The only thing not working now is the ability to define a range of \x  
characters in a regex.

So, this /^[a-zA-Z\xE4]\*?&/u will validate that a string is allowed  
to have an ä in it. Perfect.

But… this fails /^[a-zA-Z\xE4-\xE6]\*?&/u

But… this works /^[a-zA-Z\xE4\xE5\xE6]\*?&/u

I’ve boiled the experiments down to realizing I can’t define a range  
with \x

Is this just one of those things that just doesn’t work yet WRT Ruby/  
Rails/UTF8, or is there another syntax? I’ve scoured all the regex  
docs I can find.

–  
def gw  
acts\_as\_n00b  
writes\_at(www.railsdev.ws)  
end
