Is there an editor or plugin for more potent regular expressions?
Regular expressions are great for text 开发者_StackOverflow中文版editing. But sometimes they aren't quite enough. For example, say I have a text with 1000 sentences, with the first character in lowercase:
my name is Foo. hello, how are you? i really like this forum. ... etc.
And I want to convert them so that the first letter is capitalized. This IS possible with regular expressions, but the regular expression you need is very long and untidy. One of the things I like the most of regexs is the possibility to catch parts of the string in parenthesis and use them with $i or \i or whatever for replacement.
My question is: do you know an editor or plugin for an editor where you can process this capturing groups in some sort of language (say, Python?). This would allow us to do such things as:
search for:
^(.)(.*)$ and replace that with: toUpperCase($1)$2If you know one such system, please let me know. Thanks in advance,
Manuel
Regexbuddy for the win. Jeff Atwood's blog (Coding Horror) mentions it a few times.
Awk offers such a mix of Regex integration with imperative programming.
Try GVim - if you are (or are prepared to get) comfortable with the vi shortcuts.
http://www.vim.org/
Another one of course is perl from the command line.
GNU Emacs can do it as well (if you don't mind Emacs Lisp and the uncommon GUI). It still uses the old POSIX Regex syntax, not the new Perl one (which means you have to escape capturing group parentheses).
Search
^\(.\)
Replace by
\,(upcase \1)
and you are done. You can of course do it interactively, and you can also call your own Lisp macros from there, of course.
Komodo Edit allows you to create code snippets in several scripting languages (including Python, Perl, and PHP) that you can execute on selected text (or, I believe, across files.)
So if you want to run a small script in your editor that went through every line (or every 27 lines) and capitalized the first letter you could do it in this editor and save it as a code snippet to run later.
Further, it allows you to create dialogues to fill out portions of your code so you could write the code once and then run arbitrary python code on whatever regular expression you needed without ever touching the base script again.
UltraEdit has a complete core JavaScript engine built-in, including regex capabilities. The scripting engine has full access to UE's DOM, so it looks like that might work for you.
Various editors have their own extensions to regex syntax, but I find it easier to write a short program more often than 1) learning a new syntax, or 2) learning a new editor. But then I already know how to program. :)
Textpad has escape codes like \U
for uppercase, for your example, along with others.
精彩评论