Regex returns no match in Dart but works in online regex testers

前端 未结 1 343
后悔当初
后悔当初 2021-01-23 13:43

I have built a regex which should match valid HTTP headers. It works, sort of, on regexr: https://regexr.com/4pnk9, with regex ^([\\w\\-])+:(?!\\s*$).+$. I am using

1条回答
  •  囚心锁ツ
    2021-01-23 13:53

    You may either use

    r"^([\w-])+:(?!\s*$).+$"
    

    or

    "^([\\w-])+:(?!\\s*\$).+\$"
    

    Note that inside a non-raw string literal, the double backslashes stand for a single literal backslash. In a raw string literal, you do not need to escape the $ symbol and you only need a single backslash to form a regex escape.

    0 讨论(0)
提交回复
热议问题