多行正则求助
字符串如下MODULE
{
name = ModuleEnginesFX
thrustVectorTransformName = thrustTransform
exhaustDamage = True
ignitionThreshold = 0.1
minThrust = 0
maxThrust = 16
heatProduction = 150
fxOffset = 0, 0, 0.01
localPosition = 0, 0, 0.12
EngineType = LiquidFuel
exhaustDamageDistanceOffset = 0.12
PROPELLANT
{
name = LiquidFuel
ratio = 0.9
DrawGauge = True
}
PROPELLANT
{
name = Oxidizer
ratio = 1.1
}
atmosphereCurve
{
key = 0 290
key = 1 275
key = 7 0.001
}
}
以上文本中如何获取
atmosphereCurve
{
key = 0 290 (目的是能够获取变量 290 并且需要替换为其它数字,且此大括弧内的行数不定)
key = 1 275(目的是能够获取变量 275 并且需要替换)
key = 7 0.001
}
谢谢
StringRegExp($sSource, '(?si)\h*atmosphereCurve.+?}', 1) afan 发表于 2019-8-3 17:38
这么快?
多谢大神~ dtooboss 发表于 2019-8-3 17:41
这么快?
多谢大神~
不客气
替换 Key0 Key1值示例
Local $sSource = _
' MODULE' & @CRLF & _
' {' & @CRLF & _
' name = ModuleEnginesFX' & @CRLF & _
' thrustVectorTransformName = thrustTransform' & @CRLF & _
' exhaustDamage = True' & @CRLF & _
' ignitionThreshold = 0.1' & @CRLF & _
' minThrust = 0' & @CRLF & _
' maxThrust = 16' & @CRLF & _
' heatProduction = 150' & @CRLF & _
' fxOffset = 0, 0, 0.01' & @CRLF & _
' localPosition = 0, 0, 0.12' & @CRLF & _
' EngineType = LiquidFuel' & @CRLF & _
' exhaustDamageDistanceOffset = 0.12' & @CRLF & _
' PROPELLANT' & @CRLF & _
' {' & @CRLF & _
' name = LiquidFuel' & @CRLF & _
' ratio = 0.9' & @CRLF & _
' DrawGauge = True' & @CRLF & _
' }' & @CRLF & _
' PROPELLANT' & @CRLF & _
' {' & @CRLF & _
' name = Oxidizer' & @CRLF & _
' ratio = 1.1' & @CRLF & _
' }' & @CRLF & _
' atmosphereCurve' & @CRLF & _
' {' & @CRLF & _
' key = 0 290' & @CRLF & _
' key = 1 275' & @CRLF & _
' key = 7 0.001' & @CRLF & _
' key = X VVVV' & @CRLF & _
' }' & @CRLF & _
' }'
;~ MsgBox(0, '源字符串', $sSource)
Local $v0 = 12345
Local $v1 = 8888.999
Local $sSRERe = StringRegExpReplace($sSource, '(?si)(Key\h*\=\h*0\h+)[\d.]+(.+?\s+Key\h*\=\h*1\h+)[\d.]+', '${1}' & $v0 & '${2}' & $v1)
MsgBox(0, '替换结果', $sSRERe)
页:
[1]