So finally I’ve started into Regular Expressions. π
After been consistently realising the need for getting all wet in RegEx but fearing the cold waters, I started on RegEx yesterday when I built a validation class in PHP for a project that I’m working on, heavily using RegEx. About 99% of validation is being done by way of RegEx & I know that many tasks can be done with RegEx quite efficiently, as someone told me sometime back that RegEx are resource hungry if not optimally used, I simply built this class using RegEx just to see that I too can do it. π
I knew RegEx are great but working with them is more cool, its just amazing that how some small tit bits of illeligible strings can match text with such precision.
For example, take into account this RegEx that I wrote to validate a person’s name.
[code]
^([a-zA-zs]{4,32})$
[/code]
This RegEx will allow only alphabets(in either case) and white spaces in the text with a minimum length of 4 & a maximum length of 32. No numbers or special characters allowed as whosoever heard of a name like Amit-Gupta_09? π
Doing RegEx has been made wonderful by The Regulator. Its a FREE RegEx testing tool with great features & I’d recommend it to anyone writing RegEx. It can analyse your RegEx to tell you what your pattern will do & you can enter an input to check if your RegEx is working or not. π
The Regulator is done in .NET & requires you to have .NET Framework installed on your machine before you install The Regulator. If you don’t have .NET Framework, then you can get v1.1 from Microsoft.com.
Another in-despensable resource is the RegEx Library where you can get hundreds of RegEx for various tasks for free. π Also, you wouldn’t want to miss out on Regular-Expressions.info as its a good reference for using RegEx, with a detailed RegEx Tutorial. I saved all of that tutorial to browse & learn while offline but I’m ashamed to say that like many things I know, I learned RegEx also by trying them out live instead of reading a tut on it & then applying it. π³
Will this mean an end to my dependence on others for RegEx? Certainly not but it will definitely lessen my dependence on others, allowing them to breathe. π π
Hello!
This is Ashok Srivastav working as a software engineer.I would like to ask you aregular expression for Time(24 hrs) that means 11:00:00 or 23:00:00
Ashok, I don’t quite get your question? Are you asking for a RegEx to validate time format or something or what?
You can try this RegEx, though I don’t consider myself to be anything but a n00b in RegEx myself!! π
<!– Author Edit –>
@Amit: I think a String like 23:23:5959:5959 would be recognized as ‘true’ with your regexpression.
Ali, no point in bashing up other people unnecessarily. If you want to do that, do it elsewhere, not my websites.
Nah, you are wrong here, it wouldn’t be validated as ‘true’ because the RegEx will accept only 2 colons which I put in the expression. Though I won’t deny that the RegEx I gave is not wrong, I mean its not fully correct, there are some instances where its not working, as I just checked it, but then I never said that I’m great shakes in it, its still greek to me!! π