Hello. This is my javascript regex pattern:
url = "http://www.amazon.com/gp";
hostname = /^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?@)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??([^#]+)?#?(\\w*)/.exec(url) || [];
// would return "www.amazon.com"
- the above regex extracting the hostname from a given url. I need this line to work using pcre (c++). as you can see, I already added another '\' to each '\' but its still doesn't work.
what are the additional changes I need to do to make it work in pcre code instead of javascript? or maybe it isn't possible and I need to build entirely new pattern to make it work in pcre?
this is a simple version of my code:
int main(void)
{
string text = "http://www.amazon.com";
string hostname;
pcrecpp::RE re("^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?@)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??([^#]+)?#?(\\w*)");
if(re.PartialMatch(text, &hostname))
{
std::cout << "match: " << hostname << "\n";
}else{
std::cout << "no match. \n";
}
return 0;
}
Thanks.