0

Here in my code I can remove a digit from the end of a string. How do i remove if there is more than one number?

i need to parse data between AM/PM and the last number for e.g.:

3:59 PMthis is me22

if i input the above i only need to get

this is me

test cases

    Alan Chettan CRN1:53 PMfffadfs3
    Alan Chettan CRN1:53 PMthis is a text message3
    +94949494 1:22 PM
    Supplement exam alert4:43 PMRohith:Daa S4 machines question paper undo? Electrical?1
    Billy Gate3:59 PM2
    +91 96330 945893:42 PMHi1
    3:59 PMthis is me22

my regex code

 ((A|P)\M)(.*)([0-9]+[0-9]|[0-9])
  • 1
    Possible duplicate of [Remove trailing numbers from string js regexp](https://stackoverflow.com/questions/27690005/remove-trailing-numbers-from-string-js-regexp) – Nope Jun 26 '17 at 13:33
  • Please review the question and fix the requirements. It does not seem that you need to remove trailing digits judging by the examples and regex. – Wiktor Stribiżew Jun 26 '17 at 13:38

2 Answers2

5

Please try this string.replace(/\d+$/, "")

Sun_Sparxz
  • 969
  • 2
  • 12
  • 25
1

This extracts the text between the AM/PM and the trailing digits.

string.replace(/^.*\d{1,2}:\d\d\s*[AP]M(.*?)\d*$/, "$1");
Leo Aso
  • 11,072
  • 3
  • 22
  • 41