Regex Back-reference drops first character

I have a regex problem where I am trying to search within a string (html based) for "href=.......".
What I am trying to do is wrap the contents of href and insert it back into the html (ie replace the link with my own).
I have an exception to the rule - where if the href="##~NOT_THIS~##" then no replacement should take place.
I also need to use the original href contents within the replacement string (ie as a back-reference).

I have been using the following regex expression (the debugging version):
regexp_replace('VERY LONG HTML STRING','((href=")[^(##~NOT_THIS~##)](.+?)("))','0=\0 1=\1 2=\2 3=\3 4=\4 5=\5')
What I get is (assuming href within 'VERY LONG HTML STRING' is href="") :
0=\0 1=href="" 2=href=" 3=ttp:// 4=" 5=

My problem is that the 3rd backreference (the one I'm interested in) always drops the first character (in this case it drops the "h" in "").

I assume the problem is with the [^(##~NOT_THIS~##)] part of the expression. When I remove it, the first character is not dropped, however then the href's I want the replace to ignore are not ignored.

I'm a regex newbie, and I've killed hours and hours on this - any help to this problem much appreciated.

Many thanks


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try moving the opening capturing parenthesis before the [] thing like this:

VERY LONG HTML STRING','((href=")([^(##~NOT_THIS~##)].+?)("))','0=\0 1=\1 2=\2 3=\3 4=\4 5=\5

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JBCRAuthor Commented:
Many thanks SuperDave.
Works perfectly now.
Wish I'd posted this 6 hours ago !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.