3

I read this answer on stackoverflow that explained how a Japanese letter on a string could be detected. I tried searching for something similar to string.match() in the String Class documentation but didn't find anything.

I also tried implementing the Best Answer from this post but it didn't work as well, does anyone have a suggestion on how can this be achieved? the output of the code below is false but it should be true.

String message = 'EnglishLetters - みずずほダイレクト'; String regex = '/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/'; Pattern regexPattern = Pattern.compile(regex); Matcher regexMatcher = regexPattern.matcher(message); String replacedMessage; if(regexMatcher.find()) { system.debug('true'); } else{ System.debug('false'); } //output: false 

1 Answer 1

3

You don't wrap expressions in forward slashes when using Apex.

String regex = '/[............]/'; // ^ remove these ^ 

Working example:

String message = 'EnglishLetters - みずずほダイレクト'; String regex = '[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]'; Pattern regexPattern = Pattern.compile(regex); Matcher regexMatcher = regexPattern.matcher(message); system.assert(regexMatcher.find()); 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.