- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-02-2009 09:34 AM
(2361 views)
I know that I can use regular expressions in the Enhanced Editor to find strings. Is it possible to use regular expressions in the "Replace with:" box on the Replace window?
Thank you.
Thank you.
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I can understand how a regular expression works for finding patterns - but how would a regular expression work for replacing a string? How exactly would it replace it??
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Unix tools like SED and AWK, Perl, too, I think, have provisions for remembering the "found" string and then altering it, like changing lower case to upper case, leaving all numerics alone and deleting the characters, etc.
Probably a little to specialized for an IDE editor.
Probably a little to specialized for an IDE editor.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It is possible.
For example, enter \d in the find text box and enter 4 in the replace with box to replace all digits with 4.
There seems to be a very limited set of regular expressions that can be used however.
For example, enter \d in the find text box and enter 4 in the replace with box to replace all digits with 4.
There seems to be a very limited set of regular expressions that can be used however.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I was hoping that I might be able to do something like
find string is \a\d\a
replace string is \a_\a
to replace all strings that have an alpha followed by a digit followed by and alpha to be replaced by the original alpha, and underscore, and the original trailing alpha.
I think I am asking for a little too much. There are other editors out there that will allow me to do something like this, or I can handle it in other ways.
Thanks for your thoughts.
This thread can be closed
find string is \a\d\a
replace string is \a_\a
to replace all strings that have an alpha followed by a digit followed by and alpha to be replaced by the original alpha, and underscore, and the original trailing alpha.
I think I am asking for a little too much. There are other editors out there that will allow me to do something like this, or I can handle it in other ways.
Thanks for your thoughts.
This thread can be closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Many text editors I've used, and many programming languages, support replacement by regular expressions. The simplest case is replacing the text that is matched with new text. For example (in vi)
s/June/July/
replaces the text "June" with "July". You can also identify a part or several parts of the regular expression (typically by surrounding it/them with parentheses). The text matched by that part is replaced with new text. For example, in my text editor I can specify this regular expression as a search target:
(\c+)blank
This means "any string that starts with at least one alphabetic character followed by "blank". The parentheses around \c+ "tags" that part of the match. Then I specify this as the replacement string:
blank\1
This replaces the match with the string blank followed by the first (in our case, only) tagged expression. That is, whatever \c+ matched.
So, if I have the words "ageblank" and "sexblank" in my text, they are replaced by "blankage" and "blanksex", respectively.
s/June/July/
replaces the text "June" with "July". You can also identify a part or several parts of the regular expression (typically by surrounding it/them with parentheses). The text matched by that part is replaced with new text. For example, in my text editor I can specify this regular expression as a search target:
(\c+)blank
This means "any string that starts with at least one alphabetic character followed by "blank". The parentheses around \c+ "tags" that part of the match. Then I specify this as the replacement string:
blank\1
This replaces the match with the string blank followed by the first (in our case, only) tagged expression. That is, whatever \c+ matched.
So, if I have the words "ageblank" and "sexblank" in my text, they are replaced by "blankage" and "blanksex", respectively.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It would make sense that the enhanced editor could do what you both mention.
Indeed, the fact that a regexp check box is available would seem to imply that this is the case.
The only use I have found for this feature is to search (not replace) using the few expressions available using the > button beside the find box.
Indeed, the fact that a regexp check box is available would seem to imply that this is the case.
The only use I have found for this feature is to search (not replace) using the few expressions available using the > button beside the find box.