cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

Regex issue

keerti
Organizer

Hello,

I am trying to get a regex working but it is giving faults
even after multiple tries.

The regex should recognize purepaths containing
“/drp/statement/” and “/drp/order/” and print whatever is present after these
patterns.

Regex I have so far: [^/drp/(order|statement)/](.*)$

Value to be tested:
/drp/statement/for/12345

Expected output: for/12345

Getting output: or/12345

Issue: first letter of the output is getting cut for some
reason.

According to the documentation page, (https://community.dynatrace.com/community/display/LEARN/Useful+Regular+Expressions),
we can test our regex in the following page: http://www.regextester.com/ and this page says my regex is correct.

Can you please help me figure out why my regex is failing in Dynatrace tester?

Thanks,

Keerti

4 REPLIES 4

graeme_william1
Inactive

Keerti,

There are a few things in your regular expression that I wouldn't do, including use of [...] that looks odd to me, and the extra parentheses in the middle of the pattern. What I'd do is:

^/drp/(?:order|statement)/(.*)$

The (?: characters open a "non-collecting group" which just means that they work like ordinary parentheses and don't contribute to the result. (Anyway, you can google it.)

HTH,

-- Graeme

Thanks a lot Graeme for the explanation. Your regex worked, will google more about it. 🙂

adam_gardner
Dynatrace Champion
Dynatrace Champion

I always rely on the built in regex and testing within DT as the final say. I don't like to be at the mercy of 3rd party altering their algorithms without notice.

True, will keep that in mind for next time. 🙂