Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm playing with Go and run into something I'm unable to find in Google, although there is certainly something that exists:

I'm using the following struct:

type Syntax struct {
  name string
  extensions *regexp.Regexp

type Scanner struct {
  classifier * bayesian.Classifier
  save_file string
  name_to_syntax  map[string] *Syntax
  extensions_to_syntax  map[*regexp.Regexp] *Syntax

I'd like to perform the following using Go and I'm quoting ruby because it's how I'd do that using ruby:

test_regexpes = my_scanner.extensions_to_syntax.keys

My goal is to get an array of *regexp.Regexp .

Any idea on how to do that in a simple way ?

Thank you !

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Maybe a better question for SO. For example, I think http://stackoverflow.com/questions/1841443/iterating-over-all-the-keys-of-a-golang-map is close to what you want. The only thing missing from that answer is allocating the slice. Here are the two parts together,

testRegexps := make(*regexp.Regexp, len(myScanner.extensionsToSyntax))
i := 0
for k := range myScanner.extensionsToSyntax {
    testRegexps[i] = k
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.