need some help with find and replace
i need some help, i want to find and replace the age value and make it 7200.000… but not change any of the other text.
BEGIN “[i 0]” Id.i 0 Id.u 14649 Type Tree SubType 2 Pos.x 133.0000 Pos.y 59.00000 Age 1529.771 END
BEGIN “[i 1]” Id.i 1 Id.u 20202 Type Garbage SubType 2 Pos.x 198.0007 Pos.y 113.3049 Lifetime 1365.457 END
BEGIN “[i 2]” Id.i 2 Id.u 9337 Type Tree SubType 2 Pos.x 4.999023 Pos.y 62.23138 Age 400.000 END
BEGIN “[i 3]” Id.i 3 Id.u 9338 Type Tre7 SubType 2 Pos.x 9.386169 Pos.y 20.61072 Age 200.000 END
now as you see, i have alot of lines that state begin…type tree…age ##### end
i want to chage the ##### value to 7200.000 without changing anything else…how do i do that??
can it even be done?
only changing a part of certain lines without altering the other parts of those lines???
guy038 last edited by guy038
Quite easy to achieve, with regular expressions :-)
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
Click on the Replace All button
Et voilà !
First, it searches for the word Age, surrounded with 2 spaces (
Due to the \K form, this previous match is forgotten by the regex engine
Then, it tries to match a non empty list of characters (
But ONLY IF that list is followed with a space and the word END (
(?= END)). The syntax
(?= END)is called a look-ahead, that must be verified, but that it’s NOT part of the final text matched. So, the strings, matched, are only the strings like 1365.457, 400.000, or 200.000, located after the word Age
In the Replace zone, these different matched strings are, simply, replaced with the string 7200.000