Dono what this regular expression is doing
(?>[^\,]*\,){3}([^\,]*)[\']?
(?>[^\,]*\,){4}([^\,]*)[\']?
could any one explain me more in deatil
Dono what this regular expression is doing
(?>[^\,]*\,){3}([^\,]*)[\']?
(?>[^\,]*\,){4}([^\,]*)[\']?
could any one explain me more in deatil
There is an awesome site http://regex101.com for these needs! It describes regulars and allows you to test and debug them.
Your ones does match things like 4 (5 for the second one) values separated by commas and returns the last one as a signle matching group:
(?>...)
are atomic groups. After they have matched once they won't leave it forever.
[^\,]
matches any character except comma[^\,]*\,
means any number (even zero) of non-comma charaters, and then a sigle comma(?>[^\,]*\,){3}
means do that happend above 3 times([^\,]*)[\']?
means one more word without commas as a group and possibly one more comma.For example, in 1,,333,4,5
the first one will match 1,,333,4,
and return 4
as matched group. The second one will find 1,,333,4,5
and 5
as group.
Edit: Even more description.
Regular expression have groups. These are parts or regular expressions that can have number quantifiers -- how many times to repeat them ({3}
) and some options. Also, after regular has matched, we can find out what every group has matched.
Atomic ones, less talk, take as much forward as they can and never go back. Also, they can't be watched as described before. They are used here only due to perfomance reasons.
So, we need to take as a group the 4th word from comma-separated values. We will do it like this:
{3}
) an atomic group ((?>...)
):
*
) of any non-comma character ([^\n]
)
[^...]
means any symbol except described ones.\,
) that separates that word from the next one(...)
)
[^\,]*
\,?
or [\,]?
)
?
means 0 or 1 group before, here it's single comma.So, it starts on first word in first atomic group, takes it all, then takes a comma. After that, it is repeated 2 times more. That takes 3 first words with their commas.
After that, one non-atomic group takes the 4th word.