Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to split '_' with one more any one character in golang?

How to split ‘_’ with any one character?

for Examples,

var one = 6221c62c67bc2a98ec6f713b_h32
-> strings.Split(one, "_h")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

var one = 12345c62c67bc2a98ec6f723c_c32
-> strings.Split(one, "_c")

var one = 12345c62c67bc2a98ec6f723c_s32
-> strings.Split(one, "_s")

How to combine these? (use regex? or any idea)

strings.Split(one, "_??")

Updated:
How can i get these?

var one = 6221c62c67bc2a98ec6f713b_h32
-> [6221c62c67bc2a98ec6f713b, h, 32]

var one = 12345c62c67bc2a98ec6f723c_c34
-> [12345c62c67bc2a98ec6f723c, c, 34]

var one = 55545c62c67bc2a98ec6f723c_s37
-> [55545c62c67bc2a98ec6f723c, s, 37]

>Solution :

You can use the regex: _[a-zA-Z], for eg

str := "6221c62c67bc2a98ec6f713b_h32"
a := regexp.MustCompile("_[a-zA-Z]")
fmt.Println(a.Split(str, 2))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading