I have an Arabic string that shows date in Arabian with detail how can I get dd mm yyyy from that with regex
Ex:
الأحد 21 مايو 2017 01:20 م
i use this regex but doesn't work
^\d{2} [\u0600-\u06FF] \d{4}
what can i do ?
This regex
(\d{4}\ \d{2}:\d{2})
Will match 2017 01:20
I guess you could play around with capture groups to get it in the right order if you want to use the result afterwards.
Regex
The code is here. Arabic right to left should reverse the code.
\d\d\d\d\s\d\d:\d\d
Looking to use Regex to filter time information. My idea is as follows:
Sample Inputs:
..."sunday\":[[\"1...
..."sunday\":[[\"2...
..."sunday\":[[\"3...
...
..."sunday\":[[\"9:59...
Essentially, I am looking to filter times that come before 10:00 on Sunday. My data comes in the following format, with the preceding and latter part of the string denoted by "..." as text representing other days of the week. I am looking to create a regex that is able to accomplish this. All of the sample input should pass. Example of input that would fail:
..."sunday\":[[\"11:00...
..."sunday\":[[\"10:01...
..."sunday\":[[\"12:01...
THank you!
Try this .+?sunday.+?"[0-9]:\d+.+
It checks for anything + sunday + anything + an hour format that suits your < 10:00 requirement.
Test it here regex101
I need to make strict validation of input for a school project, time in format HH:MM am/pm. So far i've got this RegEx expression:
(([01]?[0-9]):([0-5][0-9]) ([AaPp][Mm]))
here's a working demo: http://regexr.com/3c9b5
The only problem is that it accepts times 13:00 to 19:59
What is the correct regular expresion? RegEx has always been hard for me
You can use:
\b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))
EDIT: ^ changed this from "0" to "1" to not accept 00:00
You can use this:
^([1-9]|0[1-9]|1[0-2]):[0-5][0-9] ([AaPp][Mm])$
It will accept 1:00 am, 01:00 AM, 12:00 PM, 11:00 pm, 12:59 Pm. But won't accept 00:00 am or 00:00 PM or 01:60 Am.
([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])\s*([AaPp][Mm])
For the following:
10:00AM
10:00PM
10:00am
10:00pm
10:00 pm
10:00 am
10:30PM
23:46am
This regex has 3 parts, separated by the OR operator.
Each part allows for a type of HH
They are 0[1-9], [1-9], and 1[0-2].
/(0[1-9]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))|([1-9]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))|(1[0-2]:[0-5][0-9]((\ ){0,1})((AM)|(PM)|(am)|(pm)))/
I used this regex
([0-9]{2})\\/([0-9]{2})\\/([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) (am|pm)
You can try this. Hope this helps!
String regex = "([01]?[0-9]|2[0-3]):[0-5][0-9]";
This will work for the 24 hours validation
if you are looking for the super solution that matches ALL the time case use this regular expression:
((1[0-9]|0?[1-9])(:([0-5][0-9])) ?([AaPp][Mm])?|(1[0-9]|0?[1-9]) ?([AaPp][Mm]))(\s+([A-Z]{3,5})?|$)
it matches all the following:
simple format: 12:05, 12:04PM, 1pm, 12:05 PM but not 13PM or 28AM
time zones: 12PM MST, 1:00AM MDT or 2pm NZDT
it also doesn't match 45 minute or 12. Try here:
https://regex101.com/r/OU5DM4/1
The source text is as following:
Time: 8/26/2015 12:12:12 AM
I want to extract both of time and date values, so I used this pattern:
Time: (.+)
But because of that some times the source is like this:
Time: 8/26/2015 13:13:13 Fired by event
I had to add to the pattern that my text should ends with AM or PM, but with the following pattern I don't get my considered result:
Time: (.+) AM|PM$
Would you please help me to find the correct pattern?
Note: I don't want the times like 8/26/2015 13:13:13, I want only
the times that ends with AM or PM
You could use something like this:
Time: (\d+\/\d+\/\d+ \d+:\d+:\d+)
Update: For times ending with AM/PM only you'll have to add (AM|PM) group at the end:
Time: (\d+\/\d+\/\d+ \d+:\d+:\d+) (AM|PM)
Live demo
Try this instead
Time:\s+(.+)\s+(AM|PM)$
you could use
Time:\s(.*?)\s(.*?)\s.*
Group 1 is date
Group 2 is time
However, It may be easier to just split the string on whitespace and take the second and third items
I want a regexp for matching time in HH:MM format. Here's what I have, and it works:
^[0-2][0-3]:[0-5][0-9]$
This matches everything from 00:00 to 23:59.
However, I want to change it so 0:00 and 1:00, etc are also matched as well as 00:00 and 01:30. I.e to make the leftmost digit optional, to match HH:MM as well as H:MM.
Any ideas how to make that change? I need this to work in javascript as well as php.
Your original regular expression has flaws: it wouldn't match 04:00 for example.
This may work better:
^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$
Regular Expressions for Time
HH:MM 12-hour format, optional leading 0
/^(0?[1-9]|1[0-2]):[0-5][0-9]$/
HH:MM 12-hour format, optional leading 0, mandatory meridiems (AM/PM)
/((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/
HH:MM 24-hour with leading 0
/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
HH:MM 24-hour format, optional leading 0
/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
HH:MM:SS 24-hour format with leading 0
/(?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)/
Reference and Demo
None of the above worked for me.
In the end I used:
^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$ (js engine)
Logic:
The first number (hours) is either:
a number between 0 and 19 --> [0-1]?[0-9] (allowing single digit number)
or
a number between 20 - 23 --> 2[0-3]
the second number (minutes) is always a number between 00 and 59 --> [0-5][0-9] (not allowing a single digit)
You can use this one 24H, seconds are optional
^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])(:[0-5][0-9])?$
The best would be for HH:MM without taking any risk.
^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
Amazingly I found actually all of these don't quite cover it, as they don't work for shorter format midnight of 0:0 and a few don't work for 00:00 either, I used and tested the following:
^([0-9]|0[0-9]|1?[0-9]|2[0-3]):[0-5]?[0-9]$
You can use this regular expression:
^(2[0-3]|[01]?[0-9]):([1-5]{1}[0-9])$
If you want to exclude 00:00, you can use this expression
^(2[0-3]|[01]?[0-9]):(0[1-9]{1}|[1-5]{1}[0-9])$
Second expression is better option because valid time is 00:01 to 00:59 or 0:01 to 23:59. You can use any of these upon your requirement.
Regex101 link
As you asked the left most bit optional, I have done left most and right most bit optional too, check it out
^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]?$
It matches with
0:0
00:00
00:0
0:00
23:59
01:00
00:59
The live link is available here
None of the above answers worked for me, the following one worked.
"[0-9]{2}:[0-9]{2}"
To validate 24h time, use:
^([0-1]?[0-9]|2?[0-3]|[0-9])[:\-\/]([0-5][0-9]|[0-9])$
This accepts:
22:10
2:10
2/1
...
But does not accept:
25:12
12:61
...
Description
hours:minutes with:
Mandatory am|pm or AM|PM
Mandatory leading zero 05:01 instead of 5:1
Hours from 01 up to 12
Hours does not accept 00 as in 00:16 am
Minutes from 00 up to 59
01:16 am ✅
01:16 AM ✅
01:16 ❌ (misses am|pm)
01:16 Am❌ (am must all be either lower or upper case)
1:16 am ❌ (Hours misses leading zero)
00:16 ❌ (Invalid hours value 00)
Regular Expression
To match single occurrence:
^(0[1-9]|1[0-2]):([0-5][0-9]) ((a|p)m|(A|P)M)$
To match multiple occurrences:
Remove ^ $
(0[1-9]|1[0-2]):([0-5][0-9]) ((a|p)m|(A|P)M)
You can use following regex:
^[0-1][0-9]:[0-5][0-9]$|^[2][0-3]:[0-5][0-9]$|^[2][3]:[0][0]$
Declare
private static final String TIME24HOURS_PATTERN = "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
public boolean validate(final String time) {
pattern = Pattern.compile(TIME24HOURS_PATTERN);
matcher = pattern.matcher(time);
return matcher.matches();
}
This method return "true" when String match with the Regular Expression.
A slight modification to Manish M Demblani's contribution above
handles 4am
(I got rid of the seconds section as I don't need it in my application)
^(([0-1]{0,1}[0-9]( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]))$
handles:
4am
4 am
4:00
4:00am
4:00 pm
4.30 am
etc..
The below regex will help to validate hh:mm format
^([0-1][0-9]|2[0-3]):[0-5][0-9]$
Your code will not work properly as it will not work for 01:00 type formats. You can modify it as follows.
pattern =r"^(0?[1-9]|1[0-2]):[0-5][0-9]$"
Making it less complicated we can use a variable to define our hours limits.Further we can add meridiems for more accurate results.
hours_limit = 12
pattern = r"^[1-hours_limit]:[0-5][0-9]\s?[AaPp][Mm]$"
print(re.search(pattern, "2:59 pm"))
Check this one
/^([0-1]?[0-9]|2[0-3]):([0-5]?[0-9]|5[0-9])$/
Mine is:
^(1?[0-9]|2[0-3]):[0-5][0-9]$
This is much shorter
Got it tested with several example
Match:
00:00
7:43
07:43
19:00
18:23
And doesn't match any invalid instance such as 25:76 etc ...
You can try the following
^\d{1,2}([:.]?\d{1,2})?([ ]?[a|p]m)?$
It can detect the following patterns :
2300
23:00
4 am
4am
4pm
4 pm
04:30pm
04:30 pm
4:30pm
4:30 pm
04.30pm
04.30 pm
4.30pm
4.30 pm
23:59
0000
00:00
check this masterfull timestamp detector regex I built to look for a user-specified timestamp, examples of what it will pickup include, but is most definitely NOT limited to;
8:30-9:40
09:40-09 : 50
09 : 40-09 : 50
09:40 - 09 : 50
08:00to05:00
08 : 00to05 : 00
08:00 to 05:00
8am-09pm
08h00 till 17h00
8pm-5am
08h00,21h00
06pm untill 9am
It'll also pickup many more, as long as the times include digits
Try the following
^([0-2][0-3]:[0-5][0-9])|(0?[0-9]:[0-5][0-9])$
Note: I was assuming the javascript regex engine. If it's different than that please let me know.
You can use following regex :
^[0-2]?[0-3]:[0-5][0-9]$
Only modification I have made is leftmost digit is optional. Rest of the regex is same.