• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex  RSS feed

 
John Paterson
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I am trying to use regular expression to to see if a certain string value is formatted in the correct way: 'hour:min:sec,milisec'

My code is as follow:



the boolean found is being print as false, I am not sure why, as I was expecting a true as I feel there should have been a match. Hope

someone can advise on this. Thank you.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely the [] means you are either looking for a \\d or a \\d. What about \\d{2} instead?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Square brackets define a character set so [\\d\\d] represents a character set of any single decimal digit and not TWO decimal digits. All you need to do is replace all your square brackets by round ones. If you don't actually need to extract the field values then remove all your brackets both round and square.
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try "(\\d{2}:\\d{2}:\\d{2},\\d{3})" as regex..
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try following regex expression

^[0-9]{2}[:][0-9]{2}[:][0-9]{2}[,][0-9]{3}$

for more details refer http://regexone.com/
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!