Regular expression- setting the max length of a particular word
-
martedì 31 luglio 2012 12:40
hey all,
I have been creating a pattern for a url which is something like (https?://)?(www\.)?[a-zA-Z](\.)[a-zA-Z]+(\.)[a-zA-Z]+(/)[a-zA-Z0-9]+(/)[a-zA-Z0-9]. Now the string that matches this pattern will be something like https://thevitruvianAnalogy.myname.com/sites/subsite
Now i know how to limit the size of this string by concatenating something like {30,100} at the end of this pattern which would mean that this string should be atleast 30 letters long and at max 100 letters.
NOW THE Question is how could i restrict the length of a single word. Like in the above example, how can i check the length of myname or sites or subsite, one of them but not all of them.
Regards,
Nishant
Tutte le risposte
-
martedì 31 luglio 2012 12:42
Would you please check-out below thread
Regards,
Ahmed Ibrahim
SQL Server Setup Team
My Blog
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
This can be beneficial to other community members reading the thread. -
martedì 31 luglio 2012 12:45Just need to add {0,50} for example. This will define that user can digit until 50 digits, afther that regex will get false value.
Web Developer
-
mercoledì 1 agosto 2012 09:16
Thank you guys. I think i got the answer. It was in my knowledge all along but i wasnt able to test it. If in the following pattern you want to check the value of the last word (https?://)?(www\.)?[a-zA-Z](\.)[a-zA-Z]+(\.)[a-zA-Z]+(/)[a-zA-Z0-9]+(/)[a-zA-Z0-9] then all we need to do is put that part of the expression in brackets and do the following ([a-zA-Z0-9]{5,30}) i.e. add the following {a,b} where a is the min length and b is the max length of that particular word.
Regards,
Nishant
- Contrassegnato come risposta theVitruvianAnalogy mercoledì 1 agosto 2012 09:17
- Contrassegno come risposta annullato theVitruvianAnalogy mercoledì 1 agosto 2012 09:17
- Contrassegnato come risposta theVitruvianAnalogy mercoledì 1 agosto 2012 09:17

