2

I need to check whether the text contains a date part with it.

for ex: mytext_12/26/2011_11:51_AM or someText_12/26/2011_13:51_PM have a date part it returns true.

I am not too good with expressions so looking for one. the format of the date - time part is fixed.

i got a way out for it but failing for time .

var containsDate = ~str.search(/\d{1,2}\/\d{1,2}\/\d{4}/);

it checks the date part perfectly but when i am trying for the time part i am messing it up some where .

_\d{1,2}:\d{2}_(?:AM|PM) this is the part for time but i am not able to generate the final regex by combining this two.
1
  • in 7th grade shop class, I learned this rule: "Never use a tool that you don't know how to use." Commented Dec 29, 2011 at 14:05

2 Answers 2

1

Try,

.search(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}_[0-9]{2}:[0-9]{2}_(AM|PM)/)

A good resource for regex, MDN:Regular Expressions

Sign up to request clarification or add additional context in comments.

1 Comment

it is not working for this string which is valid " Annual_12/7/2011_3:56_PM" and for a invalid string you can check for this one "Annual_12/7/2011_234234".
0

Try,

.search(/\d+\/\d+\/\d{4}_\d+:\d+_(AM|PM)/)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.