Regular Expression match day [closed] - c#

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 5 years ago.
Improve this question
I'm learning about Regex in C#, I've written the codes to check a valid day but Regex.Match is always false.
var pat = #"(today|tomorrow|yesterday)((?:\s*[+-]?\s*\d+\s*[dwym])*)"; // Can not change
Match match = Regex.Match(value, pat);
the match.Success is always false (value = 2017-07-07)
Which format can match with that pattern?

What are you actually trying to achieve? From the looks of it you are trying to match either some text (today/tomorrow/yesterday), or a date in a specific format?
Try this:
(today|tomorrow|yesterday|\d{4}-\d{2}-\d{2})
Try using a regular expression designer as well. I use Rad Software Regular Expression Designer 1.4.

Related

How to negate whole regex [closed]

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 11 months ago.
Improve this question
I have a pattern (pattern) and I want to exclude this characters in string 'test' and find all holes in this expression. Like test, but this characters will be random
For the string 'test' I expect 'test' which is not matched by pattern ()
You could use Regex#Match here:
Regex regex = new Regex(#"(XZ|RP(?!ROD)|R|DP(?!ROD)|D|ST[\d]?|WO)");
Match match = regex.Match("testRPRODRRPWO");
if (!match.Success)
{
Console.WriteLine("input does not contain pattern");
}

Searching and Extracting substring recursively with RegEx [closed]

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 5 years ago.
Improve this question
I'm wondering if there is a RegEx pattern to solve my problem.
I'm getting strings like:
"Running script A23jddie392.sql",
"Skipped script ew223.sql",
"Script 2234ffss321.sql has an error"
and so on.
Is it possible to extract the scriptname with RegEx? Maybe searching for the .sql and then going recursively to the first blank before the scriptname?
Thank you!
Here is the code:
var pattern = "\\s\\w+[.]sql";
var test = "Script 2234ffss321.sql has an error";
var match = Regex.Match(test, pattern);
if (match.Success)
{
Console.WriteLine(match.Groups[0].Value);
}

RegEx to replace a string inside a string in Visual Studio 2015 search [closed]

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've got the following string all over my code:
languageService.getString("string_from_key");
Now I want to replace "string_from_key" (with the quotation marks) with KeyClass.string_from_key.
I am struggling with the RegEx in Visual Studio 2015 to search and replace the mentioned strings all over the code. string_from_key is a changing value, thats why RegEx. Thanks in advance.
Try matching more, and then using replacement parameters:
Search:
languageService.getString\("(\w+)"\);
Replace:
languageService.getString\(KeyClass.$1\);
Double quotes are not metachars in regexes, but parentheses are. \w+ will match more or more "word" characters, but that includes underscores (because history) so is very useful for identifiers.

regular expression to accept only numbers within specific range [closed]

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 7 years ago.
Improve this question
I was trying regular expression
to accept only numbers and it should not allow to accept more than ten
^[]0,10]{0,10}$
This matches just this range of numbers: [0-9]
^([0-9])$
And then you can use $1 if you need to replace is with something else ...
Or also you can use \d instead of [0-9] like this:
^(\d)$
And if you want to accept 10, you have to use |. Some thing like this;
^(\d|10)$
As I said, this ^ regex accept both this range [0-9] and 10.
You can try this one:
^[0-9]{0,10}$

C# Regex to split string by commas that are only before "or" [closed]

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 8 years ago.
Improve this question
I would like to split the following string based on the commas that come before the "or" delimiter and on the "or", but not after. For example
Almondmilk, Coconutmilk or Soymilk Select Varieties, Half Gallon
becomes
Almondmilk
Coconutmilk
Soymilk Select Varieties, Half Gallon
Given your requirement as described:
var output = Regex.Split(input, "(?<!or.*),");
However, given your sample output it seems you want to split on 'or' as well:
var output = Regex.Split(input,
"((?<!or.*),)|(or)",
RegexOptions.ExplicitCapture);

Categories

Resources