正規表現の使用は完全にスキップします。単純な文字列比較では、正規表現は実際には必要ありません。
コード例では、インライン メソッドを使用して、dict ビルトインが辞書を生成するために使用するキー、値のタプルを生成します (ファイルの反復コードは気にしませんでした。あなたの例は正しいです)。
line="jvm.args= -Dappdynamics.com=true, -Dsomeotherparam=false, "
# Detect a line that starts with jvm.args
if line.strip().startswith('jvm.args'):
# Only interested in the args
_, _, args = line.partition('=')
# Method that will yield a key, value tuple if item can be converted
def key_value_iter(args):
for arg in args:
try:
key, value = arg.split('=')
# Yield tuple removing the -d prefix from the key
yield key.strip()[2:], value
except:
# A bad or empty value, just ignore these
pass
# Create a dict based on the yielded key, values
args = dict(key_value_iter(args.split(',')))
print args は以下を返します:
{'appdynamics.com': 'true', 'someotherparam': 'false'}
私はこれがあなたが実際に求めているものだと思います;)