Home > OS >  How to find " 2 seconds" "1 second" using java in regex?
How to find " 2 seconds" "1 second" using java in regex?

Time:06-04

I have a string like :

String time = "2 hrs 5 minutes 2 seconds" ;
or 
String time2  = "2 hrs 1 minute 1 second" ;

I have to find number space second(s) and need to remove using regex? is that possible..

I have tried using [1-9a-z ] - but its wrong. could anyone help?

CodePudding user response:

Please use

\d \sseconds?

Regex explanation

  • \d Any number
  • \s A space character
  • seconds? Match second or seconds
  • Related