Dear all,
I don't know whether this is a common feature request. But nevertheless, ... ;) (I also found nothing about it in this mailing list.)
Would it be possible to add the following feature to the normal Find dialog?
Given a string "c( 1, 22, 333 , 4444 )" in a line. I want to highlight item by item ('1', '22', etc.) by using the normal Find function (APPLE+G).
To do so I would write for instance this regexp: [,(] {0,}(.*?) {0,}[,)]
The problem is that the current Find function doesn't select only the content of the regexp group '(.*?)', it also highlight the commas and brackets.
My suggestion would be to change the Find function in such a way, that if there is at least one group specified by '()' within the regexp it only highlight the content of it. It also could select all occurrences of it at ones, if desired. This could be chosen with two options within the Find dialog, e.g. 'Match only group' and 'Match all groups'.
I don't know whether it would cost much effort to do this, but I'd find it quite useful to have such a option.
Of course, one coud write a separate command using 'Insert Snippet' but 'Insert Snippet' has some limitations.
Or is there an other way to do it with TM?
Thanks,
Hans
Hans-Joerg Bibiko wrote:
Would it be possible to add the following feature to the normal Find dialog?
Given a string "c( 1, 22, 333 , 4444 )" in a line. I want to highlight item by item ('1', '22', etc.) by using the normal Find function (APPLE+G).
To do so I would write for instance this regexp: [,(] {0,}(.*?) {0,}[,)]
You can use lookahead and lookbehind. So you could do:
(?<=[,(] )(.*?)(?= *[,)])
The only problem with this is that lookbehind can't handle variable-length patterns, so you can't quite manage the pattern you have, with any number of spaces before the item. But if you want, you can make it handle 1-4 spaces, or something, as follows:
(?:(?<=[,(] )|(?<=[,(] {2})|(?<=[,(] {3})|(?<=[,(] {4})) (.*?)(?= *[,)])
Or similar.
See the documentation for more. Oniguruma regexps are very powerful.
-Jacob
On 24 Apr 2007, at 11:51, Jacob Rus wrote:
Hans-Joerg Bibiko wrote:
Would it be possible to add the following feature to the normal Find dialog? Given a string "c( 1, 22, 333 , 4444 )" in a line. I want to highlight item by item ('1', '22', etc.) by using the normal Find function (APPLE+G). To do so I would write for instance this regexp: [,(] {0,}(.*?) {0,}[,)]
You can use lookahead and lookbehind. So you could do:
(?<=[,(] )(.*?)(?= *[,)])
The only problem with this is that lookbehind can't handle variable- length patterns, so you can't quite manage the pattern you have, with any number of spaces before the item. But if you want, you can make it handle 1-4 spaces, or something, as follows:
(?:(?<=[,(] )|(?<=[,(] {2})|(?<=[,(] {3})|(?<=[,(] {4})) (.*?)(?= *[,)])
OK. I see. Regarding to this problem I have a more general approach:
Two macros: SelectNextWord, SelectPrevWord (see attachments) (The keys are bound to CTRL+2 and CTRL+1, no scope)
With that you also can edit such a list (1, 22, 233 ) very easily and it works in any kind of text ;) If you in a word these macros select the current word
But still there is the more general topic of this thread:
The problem is that the current Find function doesn't select only the content of the regexp group '(.*?)', it also highlight the commas and brackets.
To write such lookahead/lookbehind regexp could be a bit tricky ;)
Hans
Hans-Joerg Bibiko wrote:
The problem is that the current Find function doesn't select only the content of the regexp group '(.*?)', it also highlight the commas and brackets.
To write such lookahead/lookbehind regexp could be a bit tricky ;)
Why? You just want word characters? Then you can do:
\b\w+\b
And you should get the next word. Anyway, if the commas and brackets are in a lookahead or lookbehind they won't be matched. So they won't be "highlighted" by the find function either. And if you have many things you *don't* want matched you can always make a negative lookahead/behind. I'm really not sure what the problem is.
I suggest you find a tutorial or help document about regular expressions. It should help explain the possibilities. One that I liked was the “Python Regular Expression Howto” (google it). They are very powerful, and you should be able to do what you want with them.
-Jacob