Or you could try something like https://play.golang.org/p/xkmchEgyVir

On Thursday, 1 April 2021 at 20:02:29 UTC+1 Matt KØDVB wrote:

> Use a capture group
>
> regex := regexp.MustCompile(`.*\bCore Count: (\d+)`)
> result := regex.FindAllStringSubmatch(raw, -1) 
>
> https://play.golang.org/p/r_TxhVZVfzE
>
> See also https://www.youtube.com/watch?v=XCE0psygwj8
>
> On Apr 1, 2021, at 12:32 PM, Artur Vianna <lordho...@gmail.com> wrote:
>
> Try the regex: "Core Count: [0-9]+", then split on ":" and select the 
> second part.
>
> On Thu, 1 Apr 2021, 15:28 Sharan Guhan, <shar...@gmail.com> wrote:
>
>> Hi Experts,
>>
>> New to Golang and finding it non trivial to achieve the below efficiently 
>> :-) Any pointers will help..
>>
>> I have a huge string as below  .. Now from this I want to extract the 
>> number "18" after "Core count".. I was thinking of walking through each 
>> string with Spilt("\n"), but that will make it slower. I also tried 
>> strings.Index with "Core count", but unable to see how to pull the 18 from 
>> this..
>>
>> Sharan
>>
>>
>> "Version: Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
>> Voltage: 1.6 V
>> External Clock: 100 MHz
>> Max Speed: 4000 MHz
>> Current Speed: 2300 MHz
>> Status: Populated, Enabled
>> Upgrade: Socket LGA3647-1
>> L1 Cache Handle: 0x004D
>> L2 Cache Handle: 0x004E
>> L3 Cache Handle: 0x004F
>> Serial Number: Not Specified
>> Asset Tag: UNKNOWN
>> Part Number: Not Specified
>> Core Count: 18"
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAGOT8aq8btVfAYWCpGz69cvPG_OQomNGyUjBg7oa85%2BAKqp7yQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/CAGOT8aq8btVfAYWCpGz69cvPG_OQomNGyUjBg7oa85%2BAKqp7yQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAE%3DAWBUkNucnBM762j-3fPu%2BD8wEMbo4xe%2B4QxM40oosiqCq7w%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/CAE%3DAWBUkNucnBM762j-3fPu%2BD8wEMbo4xe%2B4QxM40oosiqCq7w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/430a46db-cf72-4caf-8d40-93f71f397b0bn%40googlegroups.com.

Reply via email to