我在用正则表达式替换“you\re”一词时遇到问题。
\n\n所有其他单词都正确更改,只是单词"you\'re"。\n我认为它在撇号之后没有解析。
\n\n我必须将单词“you”替换为“I”,将“you\'re”替换为“I\'m”。\n这会将“you”更改为“I”,但“you\re”会变为“I\” 're'因为它没有超过撇号,并且由于某种原因它认为这是单词的结尾。我必须以某种方式逃避撇号。
\n\n请参阅下面的相关代码。
\n\npackage main\n\nimport (\n "fmt"\n "math/rand"\n "regexp"\n "strings"\n "time"\n)\n\n//Function ElizaResponse to take in and return a string\nfunc ElizaResponse(str string) string {\n\n // replace := "How do you know you are"\n\n /*Regex MatchString function with isolation of the word "father"\n *with a boundry ignore case regex command.\n */\n if matched, _ := regexp.MatchString(`(?i)\\bfather\\b`, str);\n …Run Code Online (Sandbox Code Playgroud)