Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
After rx replacement, becomes two lines
#1
Hi,
The same regular expression, when executed in QM and PowerShell respectively, produces different results

Also, in QM, How to express \r?\n


Macro rxr
 
Code:
Copy      Help
_s=
;,Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
;Debug.Print "This should be 18: " & json.IntOf("nestedArray[i][j][k]")
;,Debug.Print rest.LastErrorText
_s.replacerx("(?m)^(\s*)Debug.Print (.+) & (.+)$", "$1_s.form($2, $3); out _s")
out _s

Result:
    _s.form("ConnectFailReason: ", rest.ConnectFailReason
); out _s
_s.form("This should be 18: ", json.IntOf("nestedArray[j][k]")
); out _s
    Debug.Print rest.LastErrorText

Powershell Code:

Code:
Copy      Help
$code = @'
    Debug.Print "ConnectFailReason: " & rest.ConnectFailReason
Debug.Print "This should be 18: " & json.IntOf("nestedArray[i][j][k]")
    Debug.Print rest.LastErrorText
'@
$code -replace '(?m)^(\s*)Debug.Print (.+) & (.+)$', '$1_s.form($2, $3); out _s'

Result:
    _s.form("ConnectFailReason: ", rest.ConnectFailReason); out _s
_s.form("This should be 18: ", json.IntOf("nestedArray[i][j][k]")); out _s
    Debug.Print rest.LastErrorText
[/i]
#2
Code:
Copy      Help
_s.replacerx("(?m)^(\s*)Debug.Print (.+) & ([^\r\n])$", "$1_s.form($2, $3); out _s")
;or
_s.replacerx("(?m)^(\s*)Debug.Print (.+) & ([^[]])$", "$1_s.form($2, $3); out _s")
;or
_s.replacerx("(?m)^(\s*)Debug.Print (.+) & (.+?)$", "$1_s.form($2, $3); out _s")

In the times when regex was added to QM, in PCRE . matched any character except \n. Later PCRE added option "any character except \n or \r", which now used in LA.
#3
thanks very much!


Forum Jump:


Users browsing this thread: 1 Guest(s)