Lookbehind and Start of Line Anchor
Posted: Sat Sep 19, 2009 11:51 am
Hello forum,
I am having trouble using start of line anchor together with lookbehind assertion. I appreciate your help!
What I would like to do is to define a preg_replace formulation that converts "ag ita" into "acca" or "ag ite" into "acce". The first string consists of two words and the conversion makes it into a single word. The important thing is not to have this conversion take place if "a" is preceded by other character(s).
I thought it is very easy using line anchor together with lookbehind assertion but strangely my following regex doesn't work. What could be wrong here?
preg_replace('/g(?<=^[a]) it/', 'cc', $source);
Goal:
ag ita ---> acca
but not
pag ita ---> pacca
I am having trouble using start of line anchor together with lookbehind assertion. I appreciate your help!
What I would like to do is to define a preg_replace formulation that converts "ag ita" into "acca" or "ag ite" into "acce". The first string consists of two words and the conversion makes it into a single word. The important thing is not to have this conversion take place if "a" is preceded by other character(s).
I thought it is very easy using line anchor together with lookbehind assertion but strangely my following regex doesn't work. What could be wrong here?
preg_replace('/g(?<=^[a]) it/', 'cc', $source);
Goal:
ag ita ---> acca
but not
pag ita ---> pacca