Skip to content

Instantly share code, notes, and snippets.

@xealgo
Last active October 6, 2017 20:30
Show Gist options
  • Save xealgo/e18751281dbd4a8175bffc0912dffab8 to your computer and use it in GitHub Desktop.
Save xealgo/e18751281dbd4a8175bffc0912dffab8 to your computer and use it in GitHub Desktop.
Javascript regex for matching Go code

func (ab *

([func]{1,} \([a-z]{2} \*)

Note: just change {2} to whatever length your var is.

Example:

func (hw *HelloWorld) DoSomething() {

}

: ab.

[\:]{1}[\s]*[a-z]{2}\.

Note: just change {2} to whatever length your var is.

Example:

map[string]interface{}{"key":   ab.Value}

Gorm Struct Tags

(gorm:"column:)([\w; ])+([\"]{1}[ ])

Example

x string `gorm:"column:X" ...`

Other Struct Tags

(query:")([\w,])+([\"]{1}[ ]{0,1})

(json:")([\w,])+([\"]{1}[ ]{0,1})

etc.

Remove everything up to...

[\w* ]+[`json:]+[^"(\w)]

Example

For the following Go code:

Username string `json:"user_name"`

The regex would yield

"user_name"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment