I have the following code to check if someConfigFilePath value, which comes from configuration file, matches the current filePath and must support Windows and Unix-like platforms:
regexp.MatchString(someConfigFilePath, filePath) The regex works in Unix-like platforms, but not in Windows. After some debugging, I could find out that I need to do something like this before, then regex works inside Windows:
ps := string(os.PathSeparator) someConfigFilePathReplaced = strings.ReplaceAll(someConfigFilePath, ps, "\\\\") Question is: which would be the best way to handle this kind of situation, using Golang, to accomplish support in regex regarding the path separator, for all OS platforms?
P.S.: All file paths were already handled by path/filepath.FromSlash
没有评论:
发表评论