Regular expression – What is the best way to verify the URL input by the user in the Cocoa application?

I am trying to build a self-made web browser in order to become more proficient in Cocoa. I need a good way to verify whether the user has entered a valid URL. I have tried some regular Expressions, but NSString has some interesting quirks, and I don’t like most of the back references of regular expressions I have seen.
You can start from the + (id)URLWithString:(NSString *)URLString method of NSURL, if the string format is wrong, it will return nil.

< /p>

If you need further verification, you can use baseURL, host, parameterString, path and other methods to provide you with specific components of the URL, and then you can evaluate it in any way you see fit.

I am trying to build a homemade web browser to become more proficient in Cocoa. I need a good way to verify that the user has entered a valid URL. I have tried some regular expressions , But NSString has some interesting quirks, and doesn’t like most of the regex back references I have seen.

You can download from NSURL The + (id)URLWithString:(NSString *)URLString method starts, if the string format is wrong, it returns nil.

If you need further verification, you can use Methods such as baseURL, host, parameterString, path provide you with specific components of the URL, and then you can evaluate it in any way you see fit.

Leave a Comment

Your email address will not be published.