I can't figure out how to make Zero-width positive lookbehind regex patterns work right.
The basic example i'm trying to do is a pattern that will match everything within quotes, but not the quote marks themselves. the closest I've been able to get to kindof work is: \b([^"\n]*)(?=") This is obviously sub-optimal.
The pattern that i'd use if ZWPL worked would be: (?<=")([^"]*)(?=")
Does your regex parser support ZWPL? Is there something else I can use that will imitate this function using Zero-width positive lookAHEAD? Are you planning on adding support for ZWPL?
There are a number of things that I'd like to use ZWPL for. I could match all words following the word DIM without matching the DIM, for example.
http://www.regular-expressions.info/refadv.html APPENDIX: Zero-width positive lookbehind. Matches at a position to the left of which text appears. Since regular expressions cannot be applied backwards, the test inside the lookbehind can only be plain text. Some regex flavors allow alternation of plain text options in the lookbehind.
On 08/09/2005, at 18.05, thomas Aylott wrote:
I can't figure out how to make Zero-width positive lookbehind regex patterns work right.
Is this for syntax highlight or searching within TM? The former uses oniguruma, which does support ZWPL, and the pattern you would use, should work for that -- the latter does not support ZWPL (I plan to migrate to Oniguruma for document searches as well).
On Sep 8, 2005, at 12:15 PM, Allan Odgaard wrote:
On 08/09/2005, at 18.05, thomas Aylott wrote:
I can't figure out how to make Zero-width positive lookbehind regex patterns work right.
Is this for syntax highlight or searching within TM? The former uses oniguruma, which does support ZWPL, and the pattern you would use, should work for that -- the latter does not support ZWPL (I plan to migrate to Oniguruma for document searches as well).
That could explain it. I was using searching to help me develop my regex for use in syntax highlighting.
I would also like to use ZWPL in regular searched & macros. Once you have oniguruma for searching setup i'll be able to finish the shortcut for 'select-contents-of-next-attribute' that I've been working on.
Then I'll just have to figure out how to make a command for 'select- contents-of-previous-attribute' but I have no clue how to search backwards easily.
On 08/09/2005, at 18.46, thomas Aylott wrote:
I would also like to use ZWPL in regular searched & macros. Once you have oniguruma for searching setup i'll be able to finish the shortcut for 'select-contents-of-next-attribute' that I've been working on.
Seeing how this is a macro, you could record: 1) search for "(?=.*?") 2) move right 3) search for [^"]*
One problem I see with this though, is, that you can't know if you're inside an attribute, i.e. if you are, you'd have to skip the closing " before performing the steps above.
(and now I await the request to use scope selectors in searches :) )
Then I'll just have to figure out how to make a command for 'select- contents-of-previous-attribute' but I have no clue how to search backwards easily.
With normal searches you could search backwards for " (thrice). When I do migrate to oniguruma, backwards regexp searches will be possible.