来自文本的Regexp PayPal交易ID

I run a website that accepts PayPal payments. When users have questions regarding their purchase they will send me their transaction ID through a self-coded ticket system.

I would like to turn the transactions IDs into URLs (to a link that will pull up transaction info) to make everything faster for me.

I know transaction IDs are 17 characters long. How would I go about this?

UPDATE:

When users post let us say. "Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: XXXXXX". I need to be able to turn the XXXX into a link that pulls up transaction info. I can't figure out how to create this in PHP with preg_replace, so it only formats the transaction ID into the link.

I have the link that is needed to lookup the transaction info, but I just do not know how to use regex to find the transaction ID and then wrap a link around it.

You might go for:

\b[\dA-Z]{17}\b

Which looks for a character string of length 17 with borders on both sides. If you know, it has only digits, this might be as well ~\b\d{17}\b~ but you did not elaborate on the specifications, really.


In PHP this would be:
<?php

$string = <<<DATA
When users post let us say. "Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: XXXXXXXXXXXXXXXXX". I need to be able to turn the XXXX into a link that pulls up transaction info. I can't figure out how to create this in PHP with preg_replace, so it only formats the transaction ID into the link.

I have the link that is needed to lookup the transaction info, but I just do not know how to use regex to find the transaction ID and then wrap a link around it.
DATA;

$regex = '~\b[\dA-Z]{17}\b~';

$string_with_links = preg_replace($regex, "http://www.exaple.com/id/$0", $string);
echo $string_with_links;
?>

If you know the transaction ID, then you must simply use this link :

https://www.paypal.com/__LANGUAGE__/cgi-bin/webscr?cmd=_view-a-trans&id=__TRANSACTION_ID__

where

__LANGUAGE__ is the language (2 letters, lowercase, for example en, fr, it...)

__TRANSACTION_ID__ is the 17 characterss transaction id

Sample link

https://www.paypal.com/fr/cgi-bin/webscr?cmd=_view-a-trans&id=7FB54205R7031312B

Edit

Let's say you want to extract transaction id from this text :

Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: 7FB54205R7031312B.

Then you can use this regexp : (?<=\s)([A-Z\d]{17})

Demo

Sample PHP code

$string = "Hi there, my name is John Doe. I made a purchase and I'm having issues with it. Transaction ID: 7FB54205R7031312B.";
$pattern = '/(?<=\s)([A-Z\d]{17})/';

preg_match($pattern, $string, $matches);
$transaction_ID = $matches[0];
$language = 'en';

$url = 'https://www.paypal.com/'.$language.'/cgi-bin/webscr?cmd=_view-a-trans&id='.$transaction_ID;
echo $url;

Online demo

Note

Code will also work with text like Hi I'm John Doe. transaction: 7FB54205R7031312B can you help me?