0

I need to get a line from a multiline string in golang which has common word like if the word is enabled then i need the line from multiline string once enable then we will continue.. The string is Their have a problem with the server.I have to continue the task.Hope the server will enable for everyone.Once enable then we will continue. .i am trying this golang code

package main

import (
    "fmt"
    "regexp"
)

func main() {
    s := "Their have a problem with the server.I have to continue the task.Hope the server will enable for everyone.Once enable then we will continue."
    val := "enabled"
    re := regexp.MustCompile(`[^.]*(?i)` + val + `[^.]*[\.| ]`)
    fmt.Println(re.FindAllString(s, -1))
    return
}

This is the playground link

  • This is not a regex task. Use NLP: 1) Split text into sentences, 2) Get the lemmas of the words, 3) Get the sentence that contains the `enable` as lemma. – Wiktor Stribiżew Jan 13 '23 at 09:26

1 Answers1

1

I am not really understand your question but try this:

package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "Their have a problem with the server.I have to continue the task.Hope the server will enable for everyone.Once enable then we will continue."
    val := "enable"

    for _, sentence := range strings.Split(s, ".") {
        if strings.Contains(sentence, val) {
            fmt.Println(sentence)
        }
    }
    return
}

If your string is multipleline string, you should split by '\n' first.

Hiếu Lê
  • 122
  • 6
  • Ok i Think you don't get my question the variable val is a name which i want to search in string var s. you just changed the value of var val. but the val is anything like if the value of val is within then in response it can give with from string variable s. If the value of val is continued then in response i need conitune. – Navjot Sharma Jan 16 '23 at 03:26