regular expression to accept only numbers within specific range [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 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}$

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");
}

Regular Expression match day [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 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.

C# Regex Validate two names or more [closed]

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
Good Afternoon,
I would like a regex to validate if the user typed two names or more and not only the first name, as in this example:
Ex: Fabrício (no match)
Ex:
Fabrício Oliveira (match)
Fabrício Oliveira Xavier (match)
Note: The expression must contain accents
Here's a Regex that only relies on a whitespace separator:
^\S+(\s\S+)+$
It makes these assumptions:
No name has a space, tab, or newline in it
Names are separated by exactly one space, tab, or newline
* this is based on #juharr's comment but with the parentheses to allow more than two names.
Edit: You can play around with this Regex here https://regex101.com/r/nS3hN8/1
Edit2: Added the beginning and ending anchors to the regex
Try this regular expression which matches two any length words separated by a space:
new Regex(#"\w+ \w+");
Really you could just use this:
if (Regex.Match(stringname, #"\w+\s\w+").Success)

regex to concatenate two strings in C# [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
Is it possible to concatenate two sub strings from a input string using Regex
Example : Input string "ABTTPQR 00100300250000" and I want take first two characters "AB" and first 9 digits "001003002" and concatenate these two string to one "AB001003002"
Much shorter variation using references:
Regex.Replace("ABTTPQR 00100300250000", #"^(\w{2})\w*\s(\d{9})\d+$", #"$1$2")
// = "AB001003002"
You can do as follows :
Regex regex = new Regex(#"(\w{2})\w*\s(\d{9})\d*");
var matches = regex.Matches("ABTTPQR 00100300250000");
String output = matches[0].Groups[1].Value + matches[0].Groups[2].Value;
//AB001003002
Regex Explanation:
(\w{2})\w*\s(\d{9})\d*
The (\w{2}) will match the first 2 chars, then it will look for more chars and a space \w*\s then it will match first 9 digits (\d{9}) and then will look for more digits \d*.
The () captures the matches into groups which are accessed in c# like shown in code sample: matches[0].Groups[1].Value for group 1 (chars) and matches[0].Groups[2].Value for group 2 (digits)

Regular expression for a phrase like zzz abc_2006073122 [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 need a regular expression for the following please
zzz abc_2006073122
zzz abc_def_2006073122
zzz abc_def_ghi_2006073122
I need to get the first 8 digits of the date (20060731) but i may have several _ parts before that so not quite sure what expression will get me what i need.
Thanks
string str = #"zzz abc_def_ghi_2006073122";
Regex reg = new Regex(#"^[a-zA-Z_ ]*_(?<someNamedGroup>\d{8})");
var match = reg.Match(str);
var result = match.Groups[1].Value;
The Regex is something like:
([0-9]{8})(?:[0-9]{2})$
Meaning: anchored to the end of the string, 8 digits to "take", 2 digits to ignore.
If you can't use the end of the line as anchor, you can try this:
(?:_)([0-9]{8})(?:[0-9]{2})
Meaning: a _ followed by 10 digits. Only 8 of these digits will be captured.

Categories

Resources