I have used regexreplace in this same program for over a year with much success.
I recently discovered that my main variable "data" was being blanked out. All the info had disappeared.
I traced the problem to one line. Doing a msgbox % data before the line shows the contents of data and doing a msgbox % data after the line shows nothing.
I've spent 4 hours trying to figure out what is wrong and finally decideed I need assistence.
PArt of data that matters:
data :=
<employee>
<name>Daigo Hirashi</name>
<role>Accountant</role>
<thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb>
</employee>
<resume>
<position>0.000000</position>
<total>0.000000</total>
</resume>
FoundPos1 := RegExMatch(Data, "<actor>" ,, 1)
originalactorpicture1a = <thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb>
actorpicture1 = <thumb>C:\Users\br-rm-6\Desktop\employees\Daigo_New.jpg</thumb>
CODE:
testactor1pic = <thumb>%originalactorpicture1a%</thumb>
testactor1pic2 = <thumb>%actorpicture1%</thumb
Data := RegExReplace(Data, testactor1pic , testactor1pic2,1,FoundPos1)
msgbox % data = " " at this point
END CODE
Any idea what is going on here? I haven't a clue
btw: I need starting position so I cannot use StrReplace
Thanks
Mike
regexreplace blanking out my variable
Re: regexreplace blanking out my variable
1. Exactly what actually happens when you run this script?
2. What should happen instead?
See syntax in documentation:
NewStr := RegExReplace(Haystack, NeedleRegEx, Replacement, OutputVarCount, Limit, StartingPos)
Although you can omit some parameters, you cannot omit the commas that mark their place.
Backslash is a special regex character. You can learn about regular expressions in the documentation.
Your starting position is zero?
2. What should happen instead?
See syntax in documentation:
NewStr := RegExReplace(Haystack, NeedleRegEx, Replacement, OutputVarCount, Limit, StartingPos)
Although you can omit some parameters, you cannot omit the commas that mark their place.
Backslash is a special regex character. You can learn about regular expressions in the documentation.
Your starting position is zero?
-
- Posts: 30
- Joined: 13 Feb 2021, 10:34
Re: regexreplace blanking out my variable
sorry, mixed up the code with another project.
here is the code. If you copy/paste in your editor you will see what I see. msgbox shows nothing
----------------------------------------------------------------------------------------------------------------------------
[Mod edit: [code][/code] tags added.]
here is the code. If you copy/paste in your editor you will see what I see. msgbox shows nothing
----------------------------------------------------------------------------------------------------------------------------
Code: Select all
originalactorpicture1a = "<thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb>"
actorpicture1 = "c:\users\mike\2.jpg"
data := "
<actor>
<name>Daigo Hirashi</name>
<role>Accountant</role>
<thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb>
</actor>
<resume>
<position>0.000000</position>
<total>0.000000</total>
</resume>"
MsgBox % data
FoundPos1 := RegExMatch(Data, "<actor>" ,, 1)
testactor1pic = <thumb>%originalactorpicture1a%</thumb>
testactor1pic2 = <thumb>%actorpicture1%</thumb
Data := RegExReplace(Data, testactor1pic , testactor1pic2,1,FoundPos1)
MsgBox % data
-
- Posts: 30
- Joined: 13 Feb 2021, 10:34
Re: regexreplace blanking out my variable
ywa in this example, the starting position is 0
I always use regexreplace on directory paths and never had this problem before
What should happen is <thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb> in the data variable should change to this c:\users\mike\2.jpg
but instead the data variable is made empty
I always use regexreplace on directory paths and never had this problem before
What should happen is <thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb> in the data variable should change to this c:\users\mike\2.jpg
but instead the data variable is made empty
Re: regexreplace blanking out my variable
Suggestions:
1. Read the replies to your post carefully.
2. Display some values of variables in your script.
3. See documentation when helpful.
Explained: Var := expression • Regular expressions
1. Read the replies to your post carefully.
2. Display some values of variables in your script.
3. See documentation when helpful.
Code: Select all
originalactorpicture1a := "C:\Users\br-rm-6\Desktop\employees\Daigo.jpg"
actorpicture1 := "c:\users\mike\2.jpg"
data := "
(
<actor>
<name>Daigo Hirashi</name>
<role>Accountant</role>
<thumb>C:\Users\br-rm-6\Desktop\employees\Daigo.jpg</thumb>
</actor>
<resume>
<position>0.000000</position>
<total>0.000000</total>
</resume>
)"
pos := Instr(data, "<actor>")
MsgBox, 64, Starting position, %pos%
testactor1pic = <thumb>%originalactorpicture1a%</thumb>
testactor1pic2 = <thumb>%actorpicture1%</thumb>
data := RegExReplace(data, "\Q" testactor1pic "\E", testactor1pic2,, 1, pos)
MsgBox, 64, Result, %data%
-
- Posts: 30
- Joined: 13 Feb 2021, 10:34
Re: regexreplace blanking out my variable
Wow,
I love life. everyday you learn something new. I was looking at the regex options this morning before I checked status of my question. I looked up \Q...\E. I've read this page many times but somehow always missed the part (or maybe just didn't comprehend) what was meant by "Escaping can be avoided"
Thanks so much mikeyww
I love life. everyday you learn something new. I was looking at the regex options this morning before I checked status of my question. I looked up \Q...\E. I've read this page many times but somehow always missed the part (or maybe just didn't comprehend) what was meant by "Escaping can be avoided"
Thanks so much mikeyww
Re: regexreplace blanking out my variable
You are welcome. Other bugs fixed:
1. Missing ":=" in first two lines
2. Lack of line continuation syntax
3. Extraneous <thumb> tags
4. Missing ">" in closing tag
5. Missing parameter in RegExReplace
1. Missing ":=" in first two lines
2. Lack of line continuation syntax
3. Extraneous <thumb> tags
4. Missing ">" in closing tag
5. Missing parameter in RegExReplace