I don't think there's a way to do this in grep, but before I go and try to
twist my brain around Perl, I thought I would ask:
I often want to do a search and replace on a particular word, which may be
part of one or more identifiers or just part of text, and replace it with a
different word. But sometimes the word might be capitalised, and other
times not.
For example, say I wanted to change the word 'file' to 'plot'. This word
might occur in a comment ('If the file has been loaded ...') or in variable
or function identifiers (fileList, FileType, pFileName, files, etc.).
If I want to do a search and replace and keep the initial character's case
the same, I have to do two passes, and pay close attention to which one I'm
changing (upper or lower case), so the thing is very time-consuming and
requires a lot more attention than it ought to.
Is there a way to specify that the grep replacement should match the case
of the character? I'm thinking of something like
Find: (F|f)ile
Replace: \@1(p)lot
where '\@1(p)' means replace subpattern 1 with 'p' matching the case of the
character.
Or, actually, even better and more flexibly, this would work:
Replace: \@1(P|p)lot
where '@1' means replace the first subpattern with the term in the alternation
list that corresponds to the one matched. With this, we could even do
something like this:
Find: (red|green|blue)
Replace: \@(cyan|magenta|yellow)
Is there such a beast already? I'm not seeing it. Or maybe it's just a lot
more complicated than this.
--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.