Hi just when I think I understand Regex im slapped across the face with a wet fish. Can anyone help me out here, i'm almost there but just cant quite figure the last part out.
Using the following URLs to test against and what im trying to match using the regex:
URL === Regex needs to match
---------------------------------------------------------------------
http://localhost#stq=textarea&c=all === http://localhost
http://localhost?#stq=textarea&c=all === http://localhost?
http://localhost/#stq=textarea&c=all === http://localhost/
http://localhost/?#stq=textarea&c=all === http://localhost/?
http://localhostq=textarea&c=all === http://localhost
http://localhost?q=textarea&c=all === http://localhost?
http://localhost/q=textarea&c=all === http://localhost/
http://localhost/?q=textarea&c=all === http://localhost/?
http://localhost/test#stq=textarea&c=all === http://localhost/test
http://localhost/test?#stq=textarea&c=all === http://localhost/test?
http://localhost/test/#stq=textarea&c=all === http://localhost/test/
http://localhost/test/?#stq=textarea&c=all === http://localhost/test/?
http://localhost/testq=textarea&c=all === http://localhost/test
http://localhost/test?q=textarea&c=all === http://localhost/test?
http://localhost/test/q=textarea&c=all === http://localhost/test/
http://localhost/test/?q=textarea&c=all === http://localhost/test/?
The #stq param can be changed so it's not always going to start with a #. Also the domain isn't always going to be localhost and there may or may not be a pathname.
So far what my RegEx so far but its not picking up if theres a pathname
^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i
Ive created an example here: https://regex101.com/r/TInZCN/2
Any help would be awesome!
var uri = new System.Uri("http://localhost/test/#stq=textarea&c=all");and then accessuri.Fragment?