-2

how can I find by using regular expression the "c start" pattern which is multiple times addressed. In other words, this should find only when this pattern is found more than once. Below is an example of an xml, which shows twice the "c start", so I would like to know what is the regex in order to find it?

  <c start="11111" end="1111111" />
  <c start="11111" end="222222222" />
</action>
<action
  src="abc"
  system="2222">
  <param
    name="trackID"
    value="1"
    valueType="data">
  </param>
  <param
    name="trackName"
    value="track"
    valueType="data">
  </param>
  <c start="11111" end="1111111" />
  <c start="11111" end="222222222" />

I may have the following xml which doesn't have more that once the pattern.

  <c start="11111" end="1111111" />
</action>
<action
  src="abc"
  system="2222">
  <param
    name="trackID"
    value="1"
    valueType="data">
  </param>
  <param
    name="trackName"
    value="track"
    valueType="data">
  </param>
  <c start="11111" end="1111111" />
user10573594
  • 151
  • 1
  • 2
  • 12

1 Answers1

0

Please, try this:

<c\s+start=\"(?<start>[^\"]+)\"\s+end=\"(?<end>[^\"]+)\"\s+\/>

This expression has two groups named as start and end to retrieve values from quotes.

But you can use <c\s+start=\"([^\"]+)\"\s+end=\"([^\"]+)\"\s+\/> if you don't need named groups.

You can check your regex here: https://regex101.com/

Maksym
  • 244
  • 1
  • 2
  • 18