2

I would like to write regexp in Go to match a string only if it does not contain a specific substring (-numinput) and contain another specific string (-setup).

Example, for inputStr

The following type of strings should NOT match because -numinput is present

str = "axxx yy  -setup  abc -numinput 12345678 aaa"

The following type of strings should match as -setup is present and -numinput is not present

str = "axxx yy  -setup  abc aaa"

The following type of strings should not match because -setup is not present even though -numinput is not present

str = "axxx yy abc aaa"

I came across some posts like Regular expression to match a line that doesn't contain a word?

But, I just dont understand how to do it in Golang

Flimzy
  • 68,325
  • 15
  • 126
  • 165
user1892775
  • 1,731
  • 4
  • 31
  • 52

1 Answers1

3

If you want to parse command line flags, consider using the flag package

https://golang.org/pkg/flag/

For general string related functionality, considers the strings package

https://golang.org/pkg/strings/

In your case:

strings.Contains(str, "-setup") && !strings.Contains(str, "-numinput")
user10753492
  • 630
  • 4
  • 8