How to match double quote or single quote or unquoted with regular expression?

前端 未结 3 509
后悔当初
后悔当初 2021-01-14 09:34

I am trying to grab sometext from all three types of inputs, but can\'t figure out how to deal with the unquoted case.

So far I have:

name=[\'\"](.         


        
3条回答
  •  无人共我
    2021-01-14 10:07

    Without knowing what could be after 'name=asdf', assume its whitespace or nothing
    that delimits the end.

    name= 
    (?:
         (['"])((?:(?!\1).)*)\1    # (1,2)
     |   (\S*)                     # (3)
    )
    

    Answer is $2 catted with $3

提交回复
热议问题