Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can you advice me, how solve the problem
I need get date from string.
For example:
Dear client come to our shop 20.08.2014 10:20 other text
or
Dear client come to our shop 20 august 2014 10:20 other text
Thanks.
Simply use the date pattern to extract it from the string
\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}
Here is online demo
For second pattern use
\d{2} (january|february|march|...) \d{4} \d{2}:\d{2}
I think you need to implement your custom implementation as ypur requirements is very different.
use c# built-in functions and implement your logic
String.IndexOf (http://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspx)
String.Substring (http://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx)
Note: Handle 12 months 30 days and an year with there different formats and get the substring based on that.
Try to use:
(?i)\d{1,2}\s*\.?\s*(?:\d{1,2}|January|February|March|April|May|June|July|August|September|October|November|December)\s*\.?\s*\d{2,4}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What is the regex for matching a date starting at the 4th position? I want it to return just the date and not the whole match. This is what I have.
^.{4}[2-9][0-9]{3}[0-1][0-9][0-9]{2}
DCSG20170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
DCS120170406090204-FQI-045.TOT 04-FIC-045 00060Y000878279.312500G
DCS120170406090204-FQI-046.TOT 04-FIC-046 00060Y000815050.562500G
http://regexr.com/3g0d5
You probably want a non-capturing group:
^(?:.{4})([2-9][0-9]{3}[0-1][0-9][0-9]{2})(?:.*)$
(mouse over the text at: http://regexr.com/3g0db and it will show just one group)
I don't know C#, but from my Perl perspective, I don't see any need for a regular expression. If you just want "the date" and don't need to validate it or separate it into components, just get the substring starting at position 4 (0 based) and 8 characters long.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a C# program that communicates with MySql database and I want to write current time to database column defined as TIME. Now, when I run my program the time that has been written is for example 00:00:19 and not for example 19:34:00. Why this happens and how can I solve this?
Thanks in advance
SOLUTION
This solved the problem:
DateTime.Now.ToString("yyyyMMddHHmmss")
this because the format mysql : "yyyy-MM-dd hh:mm:ss"
check the format in you programme or try to insert a String like this "2016-23-08 13:00:00"
I think the problem caused by dateTimeVariable.ToString() method of your DateTime value.
To solve this problem use dateTimeVariable.ToString("s") to convert the DateTime to standard DateTime string.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to validate a sting with regular expression.
String Should be in the NHCC-XXXXX-00 Format ,where X is a Number.
Correct strings:
NHCC-10010-00,
NHCC-78965-00,
NHCC-99654-00
Wrong strings:
NHCC-1001-00
NHCC-78965-0
NHC-99654-00
ASDF-99654-00
NHCC-F9654-00
NHCC-99654-01
Can any one help me to solve the above senario?
This should work:
"NHCC-\d{5}-00"
Demo
You need to use anchors inorder to do an exact match.
#"^NHCC-\d{5}-00$"
The regular expression you want is #"(?s)^NHCC-\d{5}-00$"
if (!Regex.IsMatch(input, #"(?s)^NHCC-\d{5}-00$"))
{
//not valid
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a class library to add a customized toolbox to a external IE browser.
I'm using SHDocVw to do the back/forward buttons (e. g.). My question is, sense this is multilingual, how can I change the buttons text...
The url give me "/en/" or "/ar/", how can i catch this?
Thanks
With the Mati Cicero answer I managed to do it.
string page = ie.LocationURL;
Regex rgx = new Regex(#"https?://[a-zA-Z0-9.-_]+(/((?'lang'ar|en)|.*))/?");
var lang = rgx.Match(page).Success ? rgx.Match(page).Groups[1].Value : "ar";
You can try the following regex, I tried to make it as much generic as I could:
https?:\/\/[a-zA-Z0-9\.\-_]+(\/((?'lang'es|en)|.*))\/?
You would then examine the group "lang" to see if a match was made.
You would aso like to add more available languages (Added ch and in):
https?:\/\/[a-zA-Z0-9\.\-_]+(\/((?'lang'es|en|ch|in)|.*))\/?
If its always the first directory;
var lang = new Uri("http://sitename.com/en/pages/default.aspx")
.Segments[1].Replace("/", string.Empty).ToLower();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I found a regular expression for the Persian Calendar in the link but it is in the yyyy/MM/dd format. Any suggestion to format to dd/MM/yyyy and MM/dd/yyyy?
(?:1[234]\d{2})(\/|\-)(?:0?[1-9]|1[0-2])(\/|\-)(?:0?[1-9]|[12][0-9]|3[01])$
Debuggex Demo
support year between 1200 and 1499
I am using this code and it works well:
First you define a constant like the following code:
public const string PersianDateRegex = #"(?:1[23]\d{2})\/(?:0?[1-9]|1[0-2])\/(?:0?[1-9]|[12][0-9]|3[01])$";
so for test it you can use the below code:
if (Regex.IsMatch(farsiDate, PersianDateRegex))
{
...
}
Try this in ASP.NET MVC for validation of a Persian date:
[RegularExpression(#"^$|^([1۱][۰-۹ 0-9]{3}[/\/]([0 ۰][۱-۶ 1-6])[/\/]([0 ۰][۱-۹ 1-9]|[۱۲12][۰-۹ 0-9]|[3۳][01۰۱])|[1۱][۰-۹ 0-9]{3}[/\/]([۰0][۷-۹ 7-9]|[1۱][۰۱۲012])[/\/]([۰0][1-9 ۱-۹]|[12۱۲][0-9 ۰-۹]|(30|۳۰)))$", ErrorMessage = "Not Valid")]