Why won’t re.groups() give me anything for my one correctly-matched group?

To the best of my knowledge, .groups() returns a tuple of remembered groups. I.e. those groups in the regular expression that are enclosed in parentheses. So if you were to write: print re.search(r'(1)’, ‘1’).groups() you would get (‘1’,) as your response. In general, .groups() will return a tuple of all the groups of objects in … Read more

Regex group capture in R with multiple capture-groups

str_match(), from the stringr package, will do this. It returns a character matrix with one column for each group in the match (and one for the whole match): > s = c(“(sometext :: 0.1231313213)”, “(moretext :: 0.111222)”) > str_match(s, “\\((.*?) :: (0\\.[0-9]+)\\)”) [,1] [,2] [,3] [1,] “(sometext :: 0.1231313213)” “sometext” “0.1231313213” [2,] “(moretext :: 0.111222)” … Read more

How to get capturing group functionality in Go regular expressions

how should I re-write these expressions? Add some Ps, as defined here: (?P<Year>\d{4})-(?P<Month>\d{2})-(?P<Day>\d{2}) Cross reference capture group names with re.SubexpNames(). And use as follows: package main import ( “fmt” “regexp” ) func main() { r := regexp.MustCompile(`(?P<Year>\d{4})-(?P<Month>\d{2})-(?P<Day>\d{2})`) fmt.Printf(“%#v\n”, r.FindStringSubmatch(`2015-05-27`)) fmt.Printf(“%#v\n”, r.SubexpNames()) }

tech