tinvalidnewseq.nim 717 B

12345678910111213141516171819202122232425
  1. discard """
  2. errormsg: "type mismatch: got <array[0..6, string], int literal(7)>"
  3. file: "tinvalidnewseq.nim"
  4. line: 15
  5. """
  6. import re, strutils
  7. type
  8. TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]]
  9. proc parseURL(url: string): TURL =
  10. #([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?
  11. var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
  12. var m: array[0..6, string] #Array with the matches
  13. newSeq(m, 7) #ERROR
  14. discard re.match(url, re(pattern), m)
  15. result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
  16. port: m[5], path: m[6].split('/'))
  17. var r: TUrl
  18. r = parseUrl(r"http://google.com/search?var=bleahdhsad")
  19. echo(r.domain)