Justin Collins
8/2/2006 6:04:00 PM
Pavel Smerk wrote:
> And once more question:
>
> In Czech, c followed by h is considered (for sorting etc.) as one
> character/grapheme ch. I need to split string to single characters
> with respect to this absurd manner.
>
> In Perl I can write
>
> split /(?<=(?![Cc][Hh]).)/, $string
>
> and it works fine.
>
> Unfortunately, Ruby does not implement/support this "zero-width
> positive look-behind assertion", so the question is how can one
> efficiently split the string in Ruby?
>
> Thanks,
>
> P.
>
Does this work?
irb(main):001:0> "czech".split(/([Cc][Hh])|/)
=> ["c", "z", "e", "ch"]
irb(main):002:0> "check czech".split(/([Cc][Hh])|/)
=> ["", "ch", "e", "c", "k", " ", "c", "z", "e", "ch"]
irb(main):003:0> "cHeck czeCh".split(/([Cc][Hh])|/)
=> ["", "cH", "e", "c", "k", " ", "c", "z", "e", "Ch"]
-Justin