Pattern Match with Japanese

version

  • elixir: 1.16.0
  • erlang: 26.2.1

Hi! When I used pattern match with japanese words like this below

String.match?("あ", ~r/[りんご]/)

It returns true, But it shouldn`t.

I tried other language like Ruby, and it returned false.
Could anyone tell me What is happening in this code?

1 Like

You need the u suffix so that the regex processes with full UTF-8 handling.

iex(1)> String.match?("あ", ~r/[りんご]/u)
false

https://hexdocs.pm/elixir/Regex.html#module-modifiers

11 Likes

@benwilson512
Thanks!

I tried your code, and it worked as I imagined.

I really appreciate your quick reply!!