0

ファイルパスからジョブ番号だけを抽出するためのこのコードが与えられました。私が見つけた例から正規表現を適切に使用する方法はわかりませんが、ファイル名の「blah_blah」部分だけを抽出できるようにしたいと考えています。ヒントや提案をいただければ幸いです。

ファイルパスの例: Q:\2463_Customer_Name....\

文字列として「顧客名」だけを取得したいのですが。

Dim numRegex As New Regex("\d+") 
Dim number As String = numRegex.Match("Q:\2456_blah_blah\file.txt").Value 

ありがとう、

4

1 に答える 1

0

VB.netでの正規表現の使用については何も知りませんが、

^[A-Z]:\\[0-9]{0,4}_(.+)\\.*$

良い出発点を提供する必要があります。バックスラッシュはバックスラッシュでエスケープされます;)。blah_blah部分の開始と終了を正確に決定するものは何ですか?アンダースコアと末尾の\?私の正規表現の例では、()にblah_blahが含まれています。

^ start of line
[A-Z] one upper case letter
:\\ followed by a colon and a backslash
[0-9]{0,4} followed by up to four digits between 0-9 (tweaking here might be necessary)
_ followed by an underscore
(.*) followed by at least one (+) arbitrary character
\\ followed by a backslash (again, escaped maybe you don't need this)
.*$ followed by any number of characters until the end of the line ($)

パターンについて詳しく知っている場合は、質問を編集してより明確にすることを検討する必要があります。blah_blahの部分などに文字だけがありますか。

于 2012-10-24T14:41:23.260 に答える