Regex: Match password in MSSQL connection string, taking quote-wrapping into account

前端 未结 1 1623
青春惊慌失措
青春惊慌失措 2021-01-23 08:29

I am dealing with MSSQL connection strings in different formats, and I need to be able to extract the password, whether or not it is wrapped in (single or double) quotes. I also

相关标签:
1条回答
  • 2021-01-23 08:48

    An infinite width lookbehind is actually works like this and is usually used like this: to make sure there is some specific pattern not immediately before the required pattern.

    Thus, the optional pattern(s) at the end of a lookbehind always turn up in the consumed match.

    You should use a consuming pattern instead:

    /Password=["']?(.*?)(?:["'];|["';]?$)/gim
    

    See the regex demo, extract Group 1 value.

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