Jump to content
Sign in to follow this  
Björn Kaiser

Fun with StringRegExpReplace

Recommended Posts

I'm trying to edit a config file with this syntax:

# General Parameters

info_txt =

info_url =

language = de

sp_mode = ASCII

hp_jetadmin = off

thinprint_port = 4000

job_rcvtmout = 0

eth_conf = 0

# Printer Port Parameters

pp1_pjl = off

pp1_panel = on

pp1_rdzv_name =

pp1_apple_ptype =

# TCP/IP Parameters

tcpip = on

ip_addr =

ip_mask =

ip_gate =

Reading the settings with StringRegExp is no problem, however, the fun begins when I try to modify settings. The reason is simple, since I'm using back-referencing, when the $Value variable is a number, that changes the reference obviously. Is there any way to mask the content of the variable so it doesn't break the reference?

Func _Set(ByRef $Config, $Setting, $Value)
             Local $RegEx = "(\n" & $Setting & ")(\s*?=\s{1})([[:print:]]*?)(\n)"
             $Config = StringRegExpReplace($Config,$RegEx,"\1\2" & $Value & "\4")
        ;~   If @error then ConsoleWrite("@error: " & @error & @CRLF)
        ;~   If @extended then ConsoleWrite("@extended: " & @extended & @CRLF)
         EndFunc  ;==>_Set

"I teleported home one nightWith Ron and Sid and Meg.Ron stole Meggie's heart awayAnd I got Sidney's leg."- A poem about matter transference beams.

Share this post

Link to post
Share on other sites

Func _Set(ByRef $Config, $Setting, $Value)
             Local $RegEx = "(\n" & $Setting & ")(\h*=\h{1})([[:print:]]+)?(\r)"
             $Config = StringRegExpReplace($Config,$RegEx,"${1}${2}" & $Value & "${4}")
       ;~    If @error then ConsoleWrite("@error: " & @error & @CRLF)
       ;~    If @extended then ConsoleWrite("@extended: " & @extended & @CRLF)
         EndFunc ;==>_Set

Edited by Siao

"be smart, drink your wine"

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...