1

Unrealscript のシリアル化されたオブジェクトから値を解析するための正規表現を作成しようとしています。その一部には、次のような行が含まれます。

(X=32.69,Y='123.321',Z="A string with commas, just to complicate things!",W=Class'Some.Class')

結果のキャプチャは次のようになります。

[
    {
        'X':32.69,
        'Y':'A string with commas, just to complicate things!',
        'Z':'Class\'Some.Class\'
    }
]

X私が欲しいのは、キー(例)と値(例)を区別できるようにすることですClass\'Some.Class\'

単純な値のセットをキャプチャするためだけに、これまでに試したパターンを次に示します (現在のところ、値内のコンマを処理しようとはしていません)。

パターン

\(((\S?)=(.+),?)+\)

データセット

(X=32,Y=3253,Z=12.21)

結果

https://regex101.com/r/gT9uU3/1

私はまだこれらの正規表現の初心者であり、助けていただければ幸いです!

前もって感謝します。

4

1 に答える 1

2

この正規表現を試して、キーと値のペアを関連付けることができます。

(?!^\()([^=,]+)=([^\0]+?)(?=,[^,]+=|\)$)

正規表現はここに住んでいます。

説明:

(?!^\()         # do not match the initial '(' character

([^=,]+)        # to match the key .. we take all from the last comma
=               # till the next '=' character

([^\0]+?)       # any combination '[^\0]' - it will be the key's value
                  # at least one digit '+'
                  # but stops in the first occurrence '?'

(?=             # What occurrence?

    ,[^,]+=     # a comma ',' and a key '[^,]+='
                  # important: without the key:
                  # the occurrence will stop in the first comma
                  # that should or should not be the delimiter-comma 

    |\)$        # OR '|':  the value can also be the last one
                  # which has not another key in sequence,
                  # so, we must accept the value
                  # which ends '$' in ')' character

)               # it is all

それが役に立てば幸い。

私の英語で申し訳ありませんが、私の説明を自由に編集するか、コメントで教えてください. =)

于 2015-09-26T00:29:11.807 に答える