Hi guy’s I’m a new user here, I’m trying to learn php on my own because there is no one to help me. I found this community better for me. If you all help me i think i also would do better.
There are some reg exp to validate an web address that i could not clearly understand. I tried to get but i couldn’t make clear sense.
Welcome to the Forum. You will certainly find a lot of very skilled, experienced and talented people here to help you.
I hope you also take the opportunity to reciprocate; provide help to others whenever you can.
To answer your specific question:
Regular Expressions can be very, very tricky. The best approach is to take it in small pieces.
In much the same way you world approach a Mathematics formula, I recommend you start with the “innermost” closures (parenthesis and square brackets).
Those groups of symbols enclosed in parenthesis make up an atomic “group” on which the operation is applied.
The square brackets are used to group “classes” such as a set of all the numerals or the entire alphabet in lowercase. a-z0-9 with the trailing plus sign means there can be any number of this type of character.
Evaluating the example you provided, we can quickly see that [-a-z0-9+&@#\/%?=~_|!:,.;] and [-a-z0-9+&@#\/%=~_|] represent a set of “possibilities”.
The (?:(?:https?|ftp):\/\/|www\.) is a standard way to describe “ftp or https or https, maybe followed by ‘www.’, but not necessarily”.
So this immediately reduces the complex and intimidating expression to a couple very simple constituent parts!
Finally, the /i at the end simply states the evaluation will be case-insensitive.
I hope that is helpful. Rather than explicitly explain each part it is better for you to apply these rules and reason it out on your own. The ‘discovery’ will be exciting and you will better remember what you have learned.
Also, using one of the innumerable Regular Expression helper applications available you can interactively experiment with these parts and pieces to gain a better understanding.