Skip to content

Commit

Permalink
Merge pull request #1 from shadowmere-xyz/detect-key-in-text
Browse files Browse the repository at this point in the history
Improve the regular expression so it can detect keys that are not in a new line
  • Loading branch information
jadolg authored Sep 25, 2024
2 parents 263a9b9 + bd5ce9b commit f33d049
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func reply(update tgbotapi.Update, bot *tgbotapi.BotAPI, reply string) {

func findServers(input string) []string {
servers := []string{}
r, err := regexp.Compile("\n+\\s*(ss://[A-Za-z0-9]+=*@.+:\\d+|ss://[A-Za-z0-9]+)")
r, err := regexp.Compile("(\n+\\s*|\\s+)(ss://[A-Za-z0-9]+=*@.+:\\d+|ss://[A-Za-z0-9]+)")
if err != nil {
log.Printf("error building RE %v", err)
return nil
Expand Down
5 changes: 4 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ ss://YWVzLTI1Ni1nY206ZmFCQW9ENTRrODdVSkc3@54.36.174.181:2376#Britain504%20%28t.m
ss://YWVzLTI1Ni1nY206S2l4THZLendqZWtHMDBybQ==@ak1394.free.www.outline.network:8080#www.outline.network%20(japan)
vmess://eyJhZGQiOiIxMTYuMjAzLjczLjM0IiwiYWlkIjoiMCIsImFscG4iOiIiLCJob3N0IjoiZ29vZ2xlLmNvbSIsImlkIjoiMmFhYzc3ZGUtYjNlNC00MDE3LTg0NWMtY2ExMzgwZjJlOGQwIiwibmV0Ijoid3MiLCJwYXRoIjoiL3RlbGVncmFtLWlkLUBwcml2YXRldnBucyIsInBvcnQiOiI4MCIsInBzIjoiMTExNyhAT3V0bGluZV9WcG4pIiwic2N5IjoiYXV0byIsInNuaSI6IiIsInRscyI6IiIsInR5cGUiOiIiLCJ2IjoiMiJ9
vless://YWVzLTI1Ni1nY206ZmFCQW9ENTRrODdVSkc3@54.36.174.181:2376#Britain504%20%28t.me
Страна: 🇳🇱 Нидерланды Срок действия: 3 дня Ключ: ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpUdTFSU2ZyakRoWGREaTlnWUYzeE9k@178.208.91.118:16942/?outline=1
`
expectedServers := []string{
"ss://YWVzLTI1Ni1nY206WTZSOXBBdHZ4eHptR0M@54.36.174.181:5002",
Expand All @@ -37,9 +39,10 @@ vless://YWVzLTI1Ni1nY206ZmFCQW9ENTRrODdVSkc3@54.36.174.181:2376#Britain504%20%28
"ss://YWVzLTI1Ni1nY206ZmFCQW9ENTRrODdVSkc3@54.36.174.181:2376",
"ss://YWVzLTI1Ni1nY206UENubkg2U1FTbmZvUzI3QDUuMzkuNzAuMTM4OjgwOTA",
"ss://YWVzLTI1Ni1nY206S2l4THZLendqZWtHMDBybQ==@ak1394.free.www.outline.network:8080",
"ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpUdTFSU2ZyakRoWGREaTlnWUYzeE9k@178.208.91.118:16942",
}

servers := findServers(sample)
assert.Len(t, servers, 7)
assert.Len(t, servers, 8)
assert.EqualValues(t, expectedServers, servers)
}

0 comments on commit f33d049

Please sign in to comment.