-1

I have the following regex and it finds a partial solution for me:

((?=(<\/))(.*?)(?:\>))

Given the Following line:

</EventSubType><OrgUnitNm>###</OrgUnitNm></test:CommonAttributes><ProductArrangementBasic><ProductId>####</ProductId></part:Asking>

The regex will give me:

</EventSubType></OrgUnitNm></test:CommonAttributes></ProductId></part:Asking>

I want just:

</test:   </part:

Any help would be great.

Thank you.

Dalton Heiland
  • 117
  • 2
  • 7

1 Answers1

1

NOTE: if you are parsing HTML, you'd better use a dedicated library for that.

I suspect you are using the regex with PCRE /U tag, like /((?=(<\/))(.*?)(?:\>))/U.

If you want to obtain just </test: and </part:, you may use a much simpler regex:

/<\/\w+:/

See the regex demo

Details:

  • < - a literal <
  • \/ - a literal /
  • \w+ - 1 or more chars from [a-zA-Z0-9_] ranges
  • : - a literal :.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563