1

レガシー システムをサポートする際に、次の形式でデータを格納するフィールド データ コレクターに直面しています。

# This is a comment <-beacuse it starts at the begining of the file
# This is a comment <- see above
# 1. Item one <- not a comment because it starts with 1.
# Description of Item 1 <- not a comment as it is after a line that starts with a number
data point 1
data point 2
data point etc
3 <-- represents number of data points under Item one

# 2. Item two <-- not a comment
# Description of item 2 <-- not a comment
data point 1
data point ..
data point 100
100
#3. Item three <--- not a comment
# Item three description
0

そのファイルを解析して各アイテムを独自のリストとして含める正しい方法はわかりません。常にではありませんが、データによって 2 つの異なるアイテムの間にランダムなスペースが追加される場合があることに注意してください。

そのようなファイルを解析する正しい方法は何ですか?

4

2 に答える 2

1

私はこれを3つのステップで行います:

  1. ファイルの先頭からすべてのコメントを削除します
  2. 正規表現で分割して、ファイル内の他のすべてのコメントを検索します (正規表現を使用して分割する方法の例については、こちらを参照してください)。
  3. 残りの行を解析する
于 2013-03-11T18:12:28.490 に答える
1

REGEX を使用して、次のように分割できます。^(?=\# ?\d+\.)

ここで例を説明: http://regex101.com/r/gB3xD1

于 2013-03-11T18:12:58.650 に答える