I am trying to write a regex which match the first ending form tag.
[^~]*
The above regex
Just make the pattern non-greedy so that it matches the smallest possible amount of characters instead of the largest possible:
]*name="loginForm"[^>]*>[^~]*?
Edit: Changed .* to [^>]* in the form tag, so that it doesn't match outside the tag.
.*
[^>]*