I want to split the string “111A1A.11111.SL.111FUND II GP_KY.zip” when last number is arise.
string=”111A1A.11111.SL.111FUND II GP_KY.zip”;
output=”FUND II GP_KY.zip”;
I tried this but no luck
var string_a = "jkjkhj89898";
var x = string_a.match(/[^d]+|d+/g);
console.log(x)
var string = "111A1A.11111.SL.111FUND II GP_KY.zip";
var lastNumberMatch = string.match(/.*(d+)(D+.*)/);
if (lastNumberMatch) {
var output = lastNumberMatch[2];
console.log(output); // "FUND II GP_KY.zip"
}
If you want to match 1 or more characters after the last digit, you can use a capture group
.*d([^dn]+)$
The pattern matches:
.*
Match the whole lined
Match a single digit([^dn]+)
Capture 1+ chars other than a newline or a digit in group 1$
End of string
If you want to match 0 or more characters in the capture group:
.*d(.*)
Example
const regex = /.*d([^dn]+)$/;
const str = "111A1A.11111.SL.111FUND II GP_KY.zip";
const match = str.match(regex);
if (match) {
console.log(match[1]);
}
Output
FUND II GP_KY.zip
const regex = /.*d([^dn]+)$/;
const str = "111A1A.11111.SL.111FUND II GP_KY.zip";
const match = str.match(regex);
if (match) {
console.log(match[1]);
}