help on a formula, please?
-
Hi, I need some help please.
I asked a question some time back on this site, and now i need another answer.
take this setup for example:
BEGIN “[i 0]” Type Wife Age 7200.000 SkinColour 0x000000ff END
BEGIN “[i 1]” Type Son Age 7200.000 SkinColour 0x000000ff END
BEGIN “[i 2]” Type Tree SubType 5 Pos.x 10.49121 Pos.y 111.7811 Age 7200.000 END
BEGIN “[i 3]” Type Tree SubType 2 Pos.x 13.77533 Pos.y 34.22266 Age 7200.000 ENDsomeone already told me how to modify the “Age” of a “Tree” earlier…
? Open the Replace dialog ( CTRL + H )
? Select the Regular expression search mode
? Preferably, check the Match case option
? Check the Wrap around option, if necessary
? In the Find What zone, type Age \K.+(?= END)
Remark : There a space, before the word Age AND after it, as well as before the word END !
? In the Replace with zone, type, simply, the string 7200.000
? Click on the Replace All button
Et voilà !but HERE IS THE QUESTION: how do i alter the steps to make sure it only includes the “Tree” Age??
-
no one knows how to search and replace the age values in the last two “Tree” lines only??
-
Is there a reason why having the same topic open twice??
This isn’t very kind, isn’t it.Cheers
Claudia -
Hello Harry,
I’m the one, who posted this reply to Clearinghouse Forsale, three months ago, about ! Refer to the link below :
https://notepad-plus-plus.org/community/topic/10848/need-some-help-with-find-and-replace/3
And indeed, reading again this old post, I just realize that I didn’t pay enough attention to the line :
now as you see, i have alot of lines that state begin…type tree…age ##### end
So, the replacement should occur, ONLY IF the lines contain the word Tree, before the word Age !
In that case, just change the search regex as :
Tree .* Age \K.+(?= END$)
REMARKS :
-
There a space, BEFORE and AFTER the words Tree and Age, and a space BEFORE the last word END !
-
I also added the
$
symbol, to be sure that we search for the word END, at the very end of each line
NOTES :
-
This time, the search regex is looking, FIRST, for any text, in a same line, between a first occurrence of the word Tree and a last occurrence of the word Age (
Tree .* Age
) -
Due to the
\K
form, this previous match is, then, forgotten by the regex engine -
Next, it tries to match a non empty list of characters
(.+)
-
But, ONLY IF that list is followed with a space and the word END, which ends the current line (
(?= END$)
). So it selects the exact number, only, between the word Age and the keyword END !
Best Regards,
guy038
-