I'm looking for a regular expression that can find and replace all the text "anytext" with "anything" in netbeans, some of the symbols also contain this text. I've done it a while back for a single file but now I want to change everything in my application & I'm struggling to get it right.
Asked
Active
Viewed 3,204 times
2
-
5If you have only text to replace, why do you need regular expressions? – Vladislav Rastrusny Nov 18 '10 at 15:00
-
1You're trying to slice butter with a katana. – darioo Nov 18 '10 at 15:02
-
basically the whole application consists of this word(text), so i'm afraid to change it manually since i can miss some of the text and the application will break..but i trust that if i use a correct regex it will not miss anything in the application – Dee-M Nov 18 '10 at 15:04
-
1Instead of manually searching and replacing code using regex (or otherwise), why not use your IDE's built-in refactoring for this task? I'm not familiar with Netbeans, but I'm sure it has support for properly renaming variables/identifiers/etc. – Bart Kiers Nov 18 '10 at 15:08
2 Answers
1
Just use find & replace to replace all instances of "anytext" with "anything". There is no difference between this and a regex find & replace, because there doesn't exist a pattern that can be easily exploited using regex. There is no difference in this case. Based on your comment, you still must manualy enter the word you want replaced and a word that will replace it.
I think you have misunderstood a bit what regular expressions are all about.

darioo
- 46,442
- 10
- 75
- 103
1
Were you looking for something like this? Where it wouldn't grab it inside word?
\banytext\b

Keng
- 52,011
- 32
- 81
- 111
-
1Be careful of `\b`: [it doesn’t mean what many think it means](http://stackoverflow.com/questions/4213800/is-there-something-like-a-counter-variable-in-regular-expression-replace/4214173#4214173). A boundary to the left means `(?(?=\w)(?<!\w)|(?<!\W))` and a boundary to the right means `?(?<=\w)(?!\w)|(?!\W))`. People are always thinking it’s defined in terms of whitespace, but it’s isn’t — not at all! – tchrist Nov 18 '10 at 15:33
-
He's right. Just keep in mind that `"anything"` will show up even though its got double-quotes around it. Also, `it.` will show up because the word boundry is in front of the period. – Keng Nov 18 '10 at 15:50