Share via

Trying to detect foreign language characters in a filename, running into problem in Powershell

Anonymous
2023-11-01T21:46:23+00:00

In Powershell, I'm trying to detect whether certain character sets appear within a filename, such as Chinese, Korean, etc. I defined a variable to hold the patterns, like this:

Define the regular expression pattern for English and other European languages

$euroPattern = "[\p{IsBasicLatin}\p{IsLatin-1Supplement}\p{IsLatinExtended-A}\p{IsLatinExtended-B}]"

Define the regular expression patterns for Korean, Chinese, and Japanese characters

$koreanPattern = "[\p{IsHangul}]"
$chinesePattern = "[\p{IsCJKUnifiedIdeographs}]"
$japanesePattern = "[\p{IsHiragana}\p{IsKatakana}]"

However, other than with the Euro languages, all of the other language patterns are returning this error message: "Array index expression is missing or not valid."

What can be going on here?

Windows for home | Windows 10 | Input and language

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2023-11-01T23:03:54+00:00

    H BlackJacquesi, hope you're doing well. I’m Ian, and I’m happy to help you today.

    You can try the regex below:

    For Korean, you can use: "[\uAC00-\uD7AF]"

    For Chinese, you can use: "[\u4E00-\u9FA5]"

    For Japanese, you can use: "[\u3040-\u309F]"

    This is a user-to-user support forum and I am a fellow user.

    I hope this helps, but please let me know if you need anything else.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-11-02T02:23:22+00:00

    Thanks that helped. Do you know how I can find the character number ranges of other languages too?

    0 comments No comments
  2. Anonymous
    2023-11-02T02:23:16+00:00

    Thanks that helped. Do you know how I can find the character number ranges of other languages too?

    0 comments No comments