Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beginner: regex ini-like file and variable within regex
#2
Macro Macro1792
Code:
Copy      Help
out
str lines=
;[config1]
;abc
;
;[config2]
;cde
;fgh
;ijk
;
;[config3]
;etc...

str var_config="config2"
str x

if findrx(lines F"(?s)^\Q[{var_config}]\E(.+?)(?:^\[|\z)" 0 8 x 1)>=0
,x.trim
,out x
else out "not found"

Also can be used API function GetPrivateProfileSection.

To add variables to a string, there are 2 ways:
1. Put F before the string, and insert variables enclosed in { }. Example: F"string {variable} string"
2. Use function str.format.
When using in regular expression, enclose variables in \Q \E. Then variable text is interpreted as simple text, not as regular expression.


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)