tags:

views:

70

answers:

2

I have regex as /^[a-zA-Z ]+$/ now I need to add support for unicode characters and so am using \p{L} like '/^[a-zA-Z ]+$\p{L}/'.

This is not working for me and I am not sure that this is correct way of using it. I am new to regex and would appreciate any guidance.

Thanks.

A: 

You've said your string must begin, then have lots of letters/spaces, then end, THEN have a unicode letter.

I'm unfamiliar with the syntax of your particular regexp library, but I suspect you want

/^[\p{L} ]+$/
dty
Unicode can be anywhere and so cant say it to be at one place only
Rachel
I meant, the example you'd posted that you'd tried was nonsensical because you were saying you wanted to match unicode letters AFTER the end of the string (represented in the regexp by $).The regexp I've given you should match any sequence of unicode letters and spaces (one or more).
dty
+1  A: 

Does this help?

/^[\p{L} ]+$/u

This will match any string that consists of spaces and any kind of letter from any language. The u flag, as Johannes pointed out, makes it match against UTF-8.

Also, I have found this site to be a lot of help for Regular Expressions in general. The link I've provided talks about regular expressions and unicode characters.

Vivin Paliath
You're missing the `u` option.
Joey
Thanks - that's what makes it match UTF-8 right?
Vivin Paliath