Regular expression to return all characters between two special characters

后端 未结 3 1124
刺人心
刺人心 2020-12-02 17:03

How would I go about using regx to return all characters between two brackets. Here is an example:

foobar[\'infoNeededHere\']ffffd
needs to return infoNeededHe         


        
3条回答
  •  鱼传尺愫
    2020-12-02 17:42

    ^.*\['(.*)'\].*$ will match a line and capture what you want in a group.

    You have to escape the [ and ] with \

    The documentation at the rubular.com proof link will explain how the expression is formed.

提交回复
热议问题