I'm really new to Go, and have been enjoying it so far. I'm trying to find a good way to split a string using a regular expression instead of a string. Thanks
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- Improve converting string to readable urls
- Regex to match charset
相关文章
- Can I run a single test in a suite?
- Optimization techniques for backtracking regex imp
- Regex to check for new line
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- Allow only 2 decimal points entry to a textbox usi
- Comparing speed of non-matching regexp
- How to access value of first index of array in Go
If you just want to split on certain characters, you can use
strings.FieldsFunc
, otherwise I'd go withregexp.FindAllString
.Use
regexp.Split
to break out string into a slice of strings with the pattern as the delimiter.You should be able to create your own split function that loops over the results of RegExp.FindAllString, placing the intervening substrings into a new array.
http://nsf.github.com/go/regexp.html?m:Regexp.FindAllString!
The regexp.Split() function would be the best way to do this.
I made a regex-split function based on the behavior of regex split function in java, c#, php.... It returns only an array of strings, without the index information.
example:
result: