开发者

Match a substring of matched string in regex

I can match the first line and open div#someId input { in the text:

div#someId input
{
padding-left: 2px;
border: 0;
background-color: white;
}

using: (^div#.*input$\n)\{

However, I want to match only the {, since I want to insert some CSS rules below by replacing { with e.g. {\nheight: 100%;

I using the Visual Studio Find and 开发者_运维知识库Replace dialog so I'm not able to create any variables or execute anything other than regex (that I'm aware of), so I assume the answer will be regex only.


You can use a group reference. \0 stores the entire match, and you can use it in your replacementment.

Edit escaping the # based on Alan Moore's comment

search:   ^div\#.*input$\n\{
replace:  \0\nheight: 100%;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜