Detect bet regex [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 8 years ago.
Improve this question
When I receive a number I want to check it against all the potential bet combinations, e.g.
L( 24, 25, 26, 27)
Would return true if I was searching for the number 24 but not 2, hope I'm clear, sorry for no code I'm a newbie.

bool ChechResult(int value)
{
String input = #"L( 24, 25, 26, 27)";
String pattern = #"\d+";
foreach (Match match in Regex.Matches(input, pattern))
{
if(value == int.Parse(match.Value))
{
return true;
}
}
return false;
}

bool foundMatch = Regex.IsMatch(subject, " " + 24 + "(?:,|\\))");

Related

Regex for double values with comma and dot [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 3 years ago.
Improve this question
void RandomRegex(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("^[0-9]*$");
if (regex.IsMatch(e.Text) && !(e.Text == "," && ((TextBox)sender).Text.Contains(e.Text)))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
How can I change it that it also accepts 0,5 with a dot like this -> 0.5
EDIT: I use this Regex to avoid letters in TextBoxes like Height for example.
I think "[0-9,\\.]+" could work here.
var pattern = "[0-9,\\.]+";
foreach( var test in new [] {"0,5", "0.5", "", "abc"})
Console.WriteLine($"{test}: {Regex.IsMatch(test, pattern)}");
0,5: True
0.5: True
: False
abc: False
As others have pointed out you could make your number parsing better.
You could:
(probably preferred) use the user's culture; or
make number parsing more resilient instead.
foreach (var test in new[] { "0.5", "0,5", "2019,11", "2,019.11", "abc" })
{
var frenchR = decimal.TryParse(test, NumberStyles.AllowThousands|NumberStyles.AllowDecimalPoint, new CultureInfo("fr-FR"), out var dec );
bool? invariantR = null;
if( !frenchR )
invariantR = decimal.TryParse(test, NumberStyles.AllowThousands|NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dec );
//var dec2 = decimal.Parse(test, CultureInfo.InvariantCulture);
Console.WriteLine($"{test,10} => {dec,10} (french={frenchR}, invariant={(invariantR?.ToString()??"not attempted")})");
}
0.5 => 0.5 (french=False, invariant=True)
0,5 => 0.5 (french=True, invariant=not attempted)
2019,11 => 2019.11 (french=True, invariant=not attempted)
2,019.11 => 2019.11 (french=False, invariant=True)
abc => 0 (french=False, invariant=False)

Spliting string with multiple conditions [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 5 years ago.
Improve this question
I have a string like this -
query = "UserId:(\"787D01FE-D108-4C83-A2E2-4B1DA3166A5C\" OR \"CCA47A4F-B4FA-405C-B34E-EC2E0B1F374C\") AND CreatedDate:[2017-06-20T06:14:11Z TO 2017-07-20T06:14:11Z] OR FirstName: Abc ";
But I want to get the result in array like this -
queries=
{
[0] UserId:(\"787D01FE-D108-4C83-A2E2-4B1DA3166A5C\" OR \"CCA47A4F-B4FA-405C-B34E-EC2E0B1F374C\")
[1] AND
[2] CreatedDate:[2017-06-20T06:14:11Z TO 2017-07-20T06:14:11Z]
[3] OR
[4] FirstName: Abc
}
Updates:
So far I had used this -
var result =
(from Match m in Regex.Matches(query , #"\[[^]]*]|\{[^}]*}|[^:]+")
select m.Value)
.ToArray();
But ended with this -
SOLUTION:
Based on the solution suggested by #NetMage I added some more variations to take care of double quotes, conditions inside parenthesis Here
UserId : ("787D01FE-D108-4C83-A2E2-4B1DA3166A5C" OR "CCA47A4F-B4FA-405C-B34E-EC2E0B1F374C") AND CreatedDate : [ 2017-06-20T06:14:11Z TO 2017-07-20T06:14:11Z ] AND (FirstName : "Abc" OR LastName : "Xyz")
Regex Expression -
(?:\w+?\s*:\s*(\(.+?\)|\".+?\"|\[.+?\]|\w+))|(?:\(\w+?\s*:\s*(\(.+?\)|\".*?\"*|\[.+?\]|\w+)\))|([A-Z]+( [A-Z]+ )?)
How does this work for you?
var pattern = #"(?:\w+? ?: ?(\(.+?\)|\[.+?\]|\w+))|([A-Z]+( [A-Z]+ )?)";
var ans = Regex.Matches(query, pattern).Cast<Match>().Select(m => m.Value).ToArray();

I need to convert this function from C# to VB.net - Convert INT to multi character string [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 5 years ago.
Improve this question
I need to convert this function from C# to VB.NET for use in SSRS report.
This function should take a number/INT and return a multi character string.
So 26 would be simple Z
but 27 would = AA
78 = AAA
79 = AAB
and so on
Function to convert:
public static String getColumnNameFromIndex(int column)
{
    column--;
    String col = Convert.ToString((char)('A' + (column % 26)));
    while (column >= 26)
    {
        column = (column / 26) -1;
        col = Convert.ToString((char)('A' + (column % 26))) + col;
    }
    return col;
}
If you're being LAZY and i mean lazy you can use http://converter.telerik.com/
Here's the output for you:
Public Shared Function getColumnNameFromIndex(column As Integer) As String
column -= 1
Dim col As String = Chr(Asc("A") + (column Mod 26))
While column >= 26
column = (column \ 26) - 1
col = Chr(Asc("A") + (column Mod 26)) & col
End While
Return col
End Function

DoString is giving error while executing expression [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am integrating Lua in my application. But I am getting error if I am adding any if condition in Expression
string ifCondition =" return 10 + 1";
string expression = "function f()\n" + ifCondition + " \nend";
state.DoString(expression);
var scriptFunc = state["ScriptFunc"] as LuaFunction;
var res = scriptFunc.Call();
Response.Write(res[0]);
If I run above code then it will work. now I am adding if condition then it will not work.
Here is my code
string ifCondition ="If (10 < 2) then \n return 10 + 1 \n else \n return 12 end";
string expression = "function f()\n" + ifCondition + " \nend";
state.DoString(expression);
var scriptFunc = state["ScriptFunc"] as LuaFunction;
var res = scriptFunc.Call();
Response.Write(res[0]);
How can I execute if condition dynamically?
string ifCondition ="If (10 < 2) then \n return 10 + 1 \n else \n return 12 end";
Lua keywords are all lower case. Change the If to if.
By the way, C# supports multiline strings, so you could write the above as:
string ifCondition = #"
if (10 < 2) then
return 10 + 1
else
return 12
end";
Not such a big deal here, but if your snippets get longer it'll get harder to maintain them as a single line.

How to validate a string contains at least 6 distinct digits using 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 8 years ago.
Improve this question
I am trying to get a Regex that checks to make sure that a supplied integer is 9 digits long and shall contain at least 6 non-repetitive digits
Example:
123456123 ------> Matches (6 different digits)
123243521 ------> Does not match (5 different digits)
This is much easier to do without a regex:
var str = "1234567890";
var isOk = str.Length >= 9
&& str.All(c => c >= '0' && c <= '9')
&& str.Distinct().Count() >= 6;

Categories

Resources