I am trying to replace a string within a text file so that it only replaces the exact match of the string.
So if the file was:
"word"
"word_1"
"word1"
"wordA"
I want to replace just word
with test_1
I would do this:
text.replace("word", "test_1")
But by doing this, I am also replacing every other word
with other text after it with that string. So the file would be like this:
"test_1"
"test_1_1"
"test_11"
"test_1A"
I want it so I can only replace word
so that it only replaces it if there are not any lowercase letters, uppercase letters or underscores after it. I want the replace to be restricted to only exact matches so if there are other strings in the file with the same text with letters, numbers or underscores after it, they will not be affected. I also want to so if any other characters are after it that are not letters, numbers or underscores will be replaced like if it was:
word"
word;
word:
Those would be fine because they do not have letters, numbers or underscores after them.
I want this so I can replace the other strings with different things like:
text.replace("word", "test_1")
text.replace("word_1", "test_2")
text.replace("word1", "test_3")
text.replace("wordA", "test_4")
So that the file will be:
test_1
test_2
test_3
test_4
How would I do this?