Hope you guys can help me.
I need to make a string that alerts me when the following conditions are met:
I have played a while with regex101 but I have not been able to reach all conditions (condition # 4 is still missing).
You can find at the following link what I have been able to make: https://regex101.com/r/Z4cE9A/5
Please note that I need matches with the following expressions characteristics:
Flavor: golang / Flag: single line
Important note: I cannot use the character "|" as it does not work properly on the system where I am going to use this string.
Any help would be more than appreciated. Thanks in advance for your support.
EDIT: I did confusion. The non functioning character is "|". However if possible is better to avoid also the "/" as I am not sure if it works. If you want we can provide me with two strings, one without the symbol "/" and one without, in case it does not work.
This should do what you want:
(?i:(http)|(error))
You can replace http
and error
with any other keywords that you are searching for.
To do that in Golang:
package main
import (
"fmt"
"regexp"
"strings"
)
func main() {
keywords := []string{
"error",
"http",
}
p := "(?i:(" + strings.Join(keywords, ")|(") + "))"
text := `
Gran Turismo Sport
Shipment Error
Attempt
https://
`
re := regexp.MustCompile(p)
fmt.Println(re.MatchString(text))
}
You can test that in Golang Playground:
https://play.golang.org/p/XOhNVBCh8Pt
EDIT:
Based on the new limitation of not being able to use the |
char, I would suggest that you search using this:
(?i:(error)?(http)?)
This will always return true (or a list of empty strings in find all) but the good thing is you can filter out all the empty strings and you will end up with the result that you want.
This is a an example of this working in Golang Playground:
https://play.golang.org/p/miVC0hdLtQc
EDIT 2: In case you want to make sure ALL the keywords are in the text change the ?
in regex with {1,}
. Also you don't need the loop any more.
(?i:(error){1,}(http){1,})
This is an an example working in Golang Playground