简体   繁体   中英

Finding sub string in a string using Regex.Match

I want to find following sub string out of my string. String which I want to find is as follow

<Canvas Canvas.Left="450" Canvas.Top="343.54" Width="202.5" Height="75" Background="#00FFFFFF">
    <:RubberBand x:Name="RubberBand1" Canvas.ZIndex="-1" LineStroke="{Binding Path=LineColor, Mode=TwoWay, ElementName=AdvancedValueBox1}" StrokeThickness="{Binding Path=LineThickness, Mode=TwoWay, ElementName=AdvancedValueBox1}" ShowLine="{Binding Path=ShowLine, Mode=TwoWay, ElementName=AdvancedValueBox1}" TargetAnchorPosition="Center" ValueAnchorPosition="LeftCenter" X1="52.5" X2="72.5" Y1="32.5" Y2="32.5" TargetId="07d572f9-2e94-4f26-bdb7-489897c92f7d" ValueId="0d4ef226-f6c5-43f0-b4fc-c3bc6a04d16d">
      <:RubberBand.TargetPropertyMappings>
        <s:String>PrimaryValueBindingProperty</s:String>
        <s:String>LabelBindingProperty</s:String>
        <s:String>AlarmBindingProperty</s:String>
        <s:String>SecondaryValueBindingProperty</s:String>
      </jcge:RubberBand.TargetPropertyMappings>
      <jcge:RubberBand.ValuePropertyMappings>
        <s:String>PrimaryValueBindingProperty</s:String>
        <s:String>LabelBindingProperty</s:String>
        <s:String>AlarmBindingProperty</s:String>
        <s:String>SecondaryValueBindingProperty</s:String>
      </:RubberBand.ValuePropertyMappings>
    </:RubberBand>
    <:TemperatureMap x:Name="Room_Status1" Canvas.Left="0" Canvas.Top="0" PrimaryValueBinding="metasys-value:Object Reference 1,813" Label="adPatch" AlarmBinding="metasys-item:Alarm extension 1" NavigateTo="metasys-item:Navigation Path 1?aliasString=Aliasing String 1"
   >
      <:TemperatureMap.Data>
        <RectangleGeometry Rect="0,0,75,75" />
      </:TemperatureMap.Data>
    </:TemperatureMap>
    <:AdvancedValueBoxAnchor x:Name="Advanced_Value_Box1" Canvas.Left="42.5" Canvas.Top="22.5" jcge:RubberBand.ID="07d572f9-2e94-4f26-bdb7-489897c92f7d" AlarmBinding="metasys-item:Alarm%20-%20Present%20Value" PrimaryValueBinding="metasys-value:" />
    <:AdvancedValueBox x:Name="AdvancedValueBox1" Canvas.Left="72.5" Canvas.Top="20" FontFamily="Arial" FontSize="11" PrimaryValueBinding="{Binding Path=PrimaryValueBinding, Mode=TwoWay, ElementName=Advanced_Value_Box1}" SecondaryValueBinding="{Binding Path=SecondaryValueBinding, Mode=TwoWay, ElementName=Advanced_Value_Box1}" AlarmBinding="{Binding Path=AlarmBinding, Mode=TwoWay, ElementName=Advanced_Value_Box1}" LabelBinding="{Binding Path=LabelBinding, Mode=TwoWay, ElementName=Advanced_Value_Box1}" jcge:RubberBand.ID="0d4ef226-f6c5-43f0-b4fc-c3bc6a04d16d" />
  </Canvas>

using Regex how can I do That I want to use following string in my pattern. It must contain following strings <Canvas , <jcge:TemperatureMap , <jcge:AdvancedValueBoxAnchor and closing tag of </Canvas>

You should probably use an XML parser for this task (eg XDocument ) on the assumption that this is not a 'one off' quick parse out, and you might not always be able to guarantee that your input (xml) is formatted in the same way.

Edit If you give an example of what XML you would like as a result I'll happily put a quick sample piece of code together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM