November 27th, 2012, 02:25 PM
Without using the split function and using only regular expression can any one please tell me how do i extract
Dearborn and MI from the below line
Norma Corder:397–857–2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
November 27th, 2012, 02:37 PM
November 27th, 2012, 02:44 PM
thanks for the expr. but i tried the first grouping with (.+) which worked fine.
Any reason why (.+?) was used??
November 27th, 2012, 03:22 PM
It's true that the non-greedy ? quantifier wasn't needed in your posted data, but I added it just in-case your actual data has or will have extra csv fields.
November 27th, 2012, 05:13 PM
(.+) or (.*) is very often a very dangerous regular expression, unless you know damn well what you are doing, as it will often match much more that you think.
Originally Posted by csvraju1985
Suppose you want to capture the first bold world in a line like this:
"The quick brown <b>fox</b> jumps over the lazy <b>dog</b>"
If you use a regular expression like /<b>(.+)<\/b>/, you will not capture "fox" as you may wish, but you will capture "fox</b> jumps over the lazy <b>dog", which is probably not what you want, because the '+' is a greedy quantifier that will match as much as it can until the final </b>. Using instead /<b>(.+?)<\/b>/ will give you a non greedy quantifier and you will capture only "fox".