Monday 20 April 2015

Regular Expression: The Use of (?

Named capture in Perl:

'Perl uses (?<NAME>pattern) to specify names captures. You have to use the %+ hash to retrieve them.

$variable =~ /(?<count>\d+)/;
print "Count is {count}";'

Cited from Can I use named groups in a Perl regex to get the results in a hash?
##################################################
"The normal capturing (pattern) has the property of capturing and group. Capturing means that the text matches the pattern inside will be captured so that you can use it with back-reference, in matching or replacement. The non-capturing group (?:pattern) doesn't have the capturing property."

"Atomic grouping (?>pattern) also has the non-capturing property, so the position of the text matched inside will not be captured." 

Cited from Confusion with Atomic Grouping - how it differs from the Grouping in regular expression of Ruby?



No comments:

Post a Comment