Skip to content

Commit

Permalink
Merge pull request #28 from gowizzard/development
Browse files Browse the repository at this point in the history
feat: Optimize regular expression for import.
  • Loading branch information
gowizzard authored Dec 26, 2022
2 parents 1568c3f + f36f6fb commit 047903a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you want to read your local `.env` file, so you can use these variables in yo

With this function the data will be loaded from the file and set as local variables. After that you can read them with standard functions, or you can use the following functions.

[Here](https://regex101.com/r/SEDjKj/3) you can find the regex expression which is used to read the environment variables.
[Here](https://regex101.com/r/SEDjKj/5) you can find the regex expression which is used to read the environment variables.

```go
err := dotenv.Import(".env")
Expand Down
2 changes: 1 addition & 1 deletion import.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type data struct {
}

// regex is to save the compiled expression.
var regex = regexp.MustCompile(`(?m)(?P<key>\w*)=["']?(?P<value>.*)(?:"|'|\b)$`)
var regex = regexp.MustCompile(`(?m)(?P<key>\w+?)=["']?(?P<value>.*?)(?:["']|\b)$`)

// Import is read the environment variable file and use regex to find
// all sub matches. After that we initialize the environment variables to local.
Expand Down

0 comments on commit 047903a

Please sign in to comment.