Is there an easy Regex expression to capture a reference code that continuously changes?

82 Views Asked by At

Let's say I have a string:

Success: Feed File Uploaded.  Use the reference code afc3d6e84df84f51944a06cccee8f59a to track these records in the logs.

What I need to capture is the reference code only, the afc3d6e84df84f51944a06cccee8f59a. It's 32 characters in this example but I'm not sure if it will always be 32. It looks like some kind of computation or hash that would probably typically have a set number of characters but the reference code will always be different. I've looked up some examples to see if there's a way to capture a string that contains an exact specific number of characters you know it to have but only saw a few things like

.{32}^ that didn't pertain to my example. Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

This is indeed a hash of some sort, and you can match it with the following regular expression:

/([0-9a-f]{32}){1,2}/

That will only match hash strings like this one, since this will match a hexadecimal string of either 32 or 64 characters long. Here's a demo that demonstrates this.