Recently, I've started exploring Typescript and I'm currently working on creating a webhook within my Google Cloud Functions.
In one of the scenarios, I have this string:
C1234567890A460450P10TS1596575969702
My objective is to utilize regex to isolate the number 1234567890
from the given string. Please note that the first character C
remains constant, while the succeeding character A
can vary and be any other alphabet.
The regex pattern that effectively captures the desired number is: (?<=C)(\d{10})(?=\w)
.
If someone could guide me on how to implement this regex in Typescript so that I can store the extracted number in a variable (for example:
const number = [the number extracted from the string] //value 1234567890
)
Edit 1:
After attempting the suggestions provided by others (which I had already experimented with before asking this question), I was able to come up with the following code snippet:
const string = request.body.string;
let regxp = new RegExp('(?<=C)(\d{10})(?=\w)');
const number = regxp.exec(string);
response.send(number);
However, executing this code resulted in an empty response.