In PHP, I want to encode ampersands that have not already been encoded. I came up with this regex
/&(?=[^a])/
It seems to work good so far, but seeing as how I'm not much of a regex expert, I am asking if any potential pitfalls can be seen in this regex?
Essentially it needs to convert &
to &
but leave the &
in &
as is (so as not to get &
)
Thanks
Update
Thanks for the answers. It seems I wasn't thinking broadly enough to cover all bases. This seems like a common pitfall of regexs themselves (having to think of all possibilities which may make your regex get false positives). It sure does beat my original one str_replace(' & ', ' & ', $string);
:)