Hi, I am using Find / Replace to remove the word 'function' from comments in some code I am working on (it causes the next word to appear as a function in CodeBrowser when editing PHP code).
I am using this Regex:
/(?<=*)([\w\s]*?) function/
I am attempting to match 'function' on any line after a * and the minimum number of word & space characters. I added the / / to delimit the regex in this email but am not using those characters in the TextMate dialog.
It seems to match correctly and highlights the characters I would expect, but when I do Replace in Current Selection (shortcut or menu) nothing is replaced. This is regardless of what I have the in replace field, whether it is a capture reference ($1), any string of characters, or empty. My hunch says it has something to do with the negative lookbehind but I don't see any way in which I've used it incorrectly so I am stumped.
Anyone have any suggestions or is this a bug?
Thanks Brandon
On 5 Sep 2011, at 05:06, Brandon M Fryslie wrote:
[…] when I do Replace in Current Selection (shortcut or menu) nothing is replaced. […] My hunch says it has something to do with the negative lookbehind but I don't see any way in which I've used it incorrectly so I am stumped.
Anyone have any suggestions or is this a bug?
This is a bug / limitation: When you Replace in Selection and your regexp matches text _outside_ the selection (via look-around assertions) it will fail because it doesn’t have access to the text outside the selection.
The only workaround is to ensure the stuff matched in the look-around assertion is also part of the selection when using Replace in Selection (or alternatively use Replace All).