Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular replacement characters
#1
Hi,

I want to replace string with a regular expression, but it doesn't work
in powershell code work

Thanks in advance for any advice and help
david

source:
My name is ┆Name┆, My country is ┆Country┆, My age is ┆Age┆, thank you!
to:
My name is $inp_Name$, My country is $inp_Country$, My age is $inp_Age$, thank you!


Macro PS_rep_work
Code:
Copy      Help
_s=
;My name is ┆Name┆, My country is ┆Country┆, My age is ┆Age┆, thank you!

str code=
;'$_s' -replace '(┆)(?<n>(?:(?!\1).)*)(\1)', '$inp_${n}$'

code.findreplace("$_s" _s)
PsCmd2 code "" _s
out _s

Macro QM_rep_notwork
Code:
Copy      Help
_s=
;My name is ┆Name┆, My country is ┆Country┆, My age is ┆Age┆, thank you!

_s.replacerx("(┆)(?<n>(?:(?!\1).)*)(\1)", "$s_${n}$")
out _s
#2
Code:
Copy      Help
_s=
;My name is ┆Name┆, My country is ┆Country┆, My age is ┆Age┆, thank you!

_s.replacerx("┆(.*?)┆" "$inp_${1}$")
out _s
#3
Works well, thank you


Forum Jump:


Users browsing this thread: 1 Guest(s)