erogol
erogol

Reputation: 13614

How to use şŞıİçÇöÖüÜĞğ characters in a regular expression in Ruby?

I tried using a regular expression to capture names:

r[1].scan(/^([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞıİçÇöÖüÜĞğ])*\s([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞıİçÇöÖüÜĞğ])*/u)

But, it gives me an error:

syntax error, unexpected $end, expecting ')'
...atches = r[1].scan(/^([A-Z]|[ŞİÇÖÜĞ])([a-z]|[şŞ�...
...  

I see that the problem is the Turkish characters I'm using. Is it possible to use unicode values of the characters in regexp? How can I use these problematic characters in this regexp?

Upvotes: 3

Views: 162

Answers (1)

Reactormonk
Reactormonk

Reputation: 21710

  1. Use ruby 1.9
  2. Go with /\p{Word}+\p{Space}\p{Word}*/

Upvotes: 2

Related Questions