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

Regex to transform return value

skung
Organizer

Please help to suggest regex to transform method return value - following are 3 possible return value. The regex should check all three and only return 4 digit code (1011) for sample 1. Sample 2 and 3 should return nothing.

sample 1: dm:node-kind()="document", dm:node-name()="null", dm:string-value()="17071807170916779075759101932402052017-07-18T07:17:10.708-05:001011"

sample 2: dm:node-kind()="document", dm:node-name()="null", dm:string-value()="2017-07-18T08:16:21.8948271-04:00CCBD1-ABCD"

sample 3: dm:node-kind()="document", dm:node-name()="null", dm:string-value()="12017-07-18T08:14:44.7388312-04:0010151015A0123-WEB9999-S"

The rule is to read and return the 4 digit code appending to timestamp if it exists as sample 1, otherwise returns nothing as sample 2&3.

Thank you.

Sharyl

5 REPLIES 5

Radu
Dynatrace Pro
Dynatrace Pro

Hi Sharyl,

A bit tricky due to the long strings, but try: .*(\d{4})"

That will skip as many characters as needed to grab the last 4 digits before a quote mark (").

Let me know if it works.

Radu

florent_duchate
Dynatrace Pro
Dynatrace Pro

Hi

if the 4 digits number is always at the end, you can try this:

([\d]{4})$

Flo

The expectation is not clear can you state the expected string properly?

skung
Organizer

Rajesh,

Client is asking to retrieve 4 digit code from a method return value. The three samples attached are three types of return message. I am asking a regex rule to be able to get the 4 digit codes when it shows up as sample 1. As far as sample 2 & 3, they should be no match and return nothing.

Sharyl

Hi Sharyl,

So It took a while to understand your requirement. Here is a sample Regular Expression you can try out:

dm:node-kind\(\)="document", dm:node-name\(\)="null", dm:string-value\(\)="(\d{4})\d*2017-\d\d-\d\dT\d\d:\d\d:\d\d.*?"

Let me know if it helps.

Regards, Rajesh.