'Regex match but do not capture with a ".*"

I have two blocks of code.

<TabItem Header="{materialDesign:PackIcon Kind=Bank, Size=24}"
                     Style="{StaticResource MaterialDesignNavigationRailTabItem}"
                     ToolTip="Example">

and

<Button Header="{materialDesign:PackIcon Kind=Bank, Size=24}"
                     Style="{StaticResource MaterialDesignNavigationRailTabItem}"
                     ToolTip="Example">

I to select the ToolTip="Example" part and replace it. However, I only want to select the ToolTip that is inside the TabItem block. I can select it with:

ToolTip\=\"(.*?)\"

That selects the one in the Button block as well. I used this StackOverflow Question to try and solve my issue, but I could not figure out how to make it work with a ".*".

So my criteria is:

  1. Must begin with '<TabItem'
  2. Must contain 'ToolTip=".*"'
  3. Must end with ">"

Is what I am trying to achieve possible? If so, how could I achieve this?



Solution 1:[1]

<TabItem.*?ToolTip="(.*?)">

if you use this regex then you will be able to get the value inside the tooltip as a list you can use them in regex with $1 here $1 will be the value inside the first tooltip and $2 will have the second if there is a second match for this regex

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pratik Agrawal