Nested regex lookahead and lookbehind
I am having problems with the nested '+'/'-' lookahead/lookbehind in regex. Let's say that I want to change the '*' in a string with '%' and let's say that '\' escapes the next character. (Turning a regex to sql like command ^^). So the string '*test*' should be changed to '%test%' , '\\*test\\*' -> '\\%test\\%' , but '\*test\*' and '\\\*test\\\*' should stay the same. I tried: (?<!\\)(?=\\\\)*\* but this doesn't work (?<!\\)((?=\\\\)*\*) ... (?<!\\(?=\\\\)*)\* ... (?=(?<!\\)(?=\\\\)*)\* ... What is the correct regex that will match the '*'s in examples given above? What is the difference