(just for the fun following my suggestion https://www.purebasic.fr/english/viewto ... 74#p577574)
Quick and dirty code taking the user input and transmitting it as is to SED. (so using SED Regex)
(SED use \1 instead of $1)
Code: Select all
; Regex And $1 parameter
; Post by BarryG » Sun Nov 28, 2021 8:47 am
; https://www.purebasic.fr/english/viewtopic.php?p=577567#p577567
; Marc56 - 2021-11-23
EnableExplicit
Enumeration
#RegExp
EndEnumeration
Procedure RegexReplaceNew(RegEx$, Text$, Replace$)
Debug "Regex source : " + Regex$
RegEx$ = ReplaceString(RegEx$, "(", "\(")
RegEx$ = ReplaceString(RegEx$, ")", "\)")
RegEx$ = RTrim(RegEx$, "g")
Debug "Regex with esc : " + Regex$
Protected Arg$ = "sed 's" + RegEx$ + Replace$ + "/g' Tmp_File.in > Tmp_File.out"
Debug "SED command line: " + Arg$
Protected Run = RunProgram("wsl", Arg$, GetTemporaryDirectory(), #PB_Program_Wait)
Protected Tmp_File$ = GetTemporaryDirectory() + "Tmp_File.out"
If FileSize(Tmp_File$) > 0
ReadFile(1, Tmp_File$)
Protected New_Line$ = ReadString(1)
CloseFile(1)
Debug "---"
Debug Text$
Debug New_Line$
Debug UCase(Left(New_Line$, 1)) + Right(New_Line$, Len(New_Line$) -1)
Else
Debug "No file"
EndIf
EndProcedure
Global Text$ = "thisStringIsGood"
If OpenFile(0, GetTemporaryDirectory() + "Tmp_File.in")
WriteString(0, "thisStringIsGood")
CloseFile(0)
Global RegEx$ = "/([A-Z])/g"
RegexReplaceNew(RegEx$ ,Text$, " \1")
Else
Debug "Can't create Temp file"
End
EndIf
DeleteFile(GetTemporaryDirectory() + "Tmp_File.in")
DeleteFile(GetTemporaryDirectory() + "Tmp_File.out")
End
(Using SED of WSL 1. If you don't have it installed, download SED from Unix Tools for Windows instead)
Code: Select all
Regex source : /([A-Z])/g
Regex with esc : /\([A-Z]\)/
SED command line: sed 's/\([A-Z]\)/ \1/g' Tmp_File.in > Tmp_File.out
---
thisStringIsGood
this String Is Good
This String Is Good
But, the simplest solution would obviously be to parse the user input (remove // and quantifiers) and use the regular expression functions of PB. But create your own regular expression filter with all the solutions, I hope you have lots of coffee and time