特定の値をチェックする方法は、文字列または数字で始まります。ここに私のコードを添付しました。 idendifierが期待どおりにエラーになっています。
code
----
Dim i As String
dim ReturnValue as boolean
i = 400087
Dim s_str As String = i.Substring(0, 1)
Dim regex As Regex = New Regex([(a - z)(A-Z)])
ReturnValue = Regex.IsMatch(s_str, Regex)
error
regx is type and cant be used as an expression
回答:
回答№1の場合は3あなたの変数は regex
, Regex
変数の型です。
そうです:
ReturnValue = Regex.IsMatch(s_str, regex)
しかし、正規表現にも欠陥があります。 [(a - z)(A-Z)]
文字に完全に一致する文字クラスを作成しています ()-az
、範囲 A-Z
スペースとそれ以外のものはありません。
あなたが手紙にマッチしたいかのように見えます。それだけのために使用する p{L}
これは、任意の言語の文字である任意の文字に一致するUnicodeプロパティです。
Dim regex As Regex = New Regex("[p{L}d]")
回答№2については2
多分あなたは意味する
Dim _regex As Regex = New Regex("[(a-z)(A-Z)]")
答え№3の2
Dim regex As Regex = New Regex([(a - z)(A-Z)]) ReturnValue = Regex.IsMatch(s_str, Regex)
注意の違いは、使用 regex.IsMatch
。また正規表現の文字列を引用する必要があります: "[(a - z)(A-Z)]"
.
最後に、その正規表現は意味をなさない。文字列内の任意の文字または開閉括弧にマッチしている。
文字列の先頭で一致させるには、開始アンカーを含める必要があります ^
、 何かのようなもの: ^[a-zA-Z]
文字列の先頭にある任意のASCII文字に一致します。
答え№4の2
文字列がaで始まるかどうかを確認する 文字 または 桁:
ReturnValue = Regex.IsMatch(s_str,"^[a-zA-Z0-9]+")
正規表現説明:
^ # Matches start of string
[a-zA-Z0-9] # Followed by any letter or number
+ # at least one letter of number
実際のところそれを見る ここに.