I'm using the VS2012 replace feature to replace some text in the editor.

I want to replace >OneWord</Label> with Content="OneWord" />.

And I want to replace >More than one word</Label> with Content="More than one word" />.

At the moment I have Find what filled with

>(\w+|[^\S\r\n]+)</Label>

and Replace with filled with

 Content="$1" />

This works for the first case where only one word is used, but not for the second case.

If I use >(\w+|[^\S\r\n]+)+</Label> I get Content="word" /> for the secod case.

How can I define my regular expressions to work in both cases?

有帮助吗?

解决方案

At the moment your are matching either a sequence of word characters \w+ or a sequence of whitespace [^\S\r\n]+.

To solve your problem, just move the quantifier and add another group:

>((\w|[^\S\r\n])+)</Label>

Your result is still in $1.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top