private static string GetFirstSubexpression(this string aString) { foreach (Regex lRegex in Utility.MakeArray( StartsWithQuantifier, StartsWithThereAreThisManyOfThese, StartsWithThisManyOfTheseAreTrue, StartsWithAnd, StartsWithOr, StartsWithOnlyIf, StartsWithIfAndOnlyIf, StartsWithNot, StartsWithNor, StartsWithXor, StartsWithNecessarilyOnlyIf, StartsWithIs, StartsWithIsTheSameAs, StartsWithAre, StartsWithTrueThat, StartsWithPossibly, StartsWithNecessarily, StartsWithTwoTermProposition)) { RegexMatch lMatch = lRegex.Exec(aString); if (lMatch != null) { return(lMatch[0]); } } return(ExpressionWithMatchedParentheses(aString)); }
public static void FillMatches(object match, out SqlInt32 Position, out SqlString MatchText) { RegexMatch rm = (RegexMatch)match; Position = rm.Position; MatchText = rm.MatchText; }
// Field santitization. User interface stuff and not part of business logic. // Checks as text is typed in and prevents copy paste from violating what we want in the boxes. private void searchTextChanged(object sender, TextChangedEventArgs e) { if (!RegexMatch.CommonNameMatch((sender as TextBox).Text)) { (sender as TextBox).Text = RegexReplace.MakeCommonName((sender as TextBox).Text); } }
protected virtual bool ScanSpanEnd(Span cur, ref int i) { int textOffset = i - StartOffset; if (cur.End != null) { RegexMatch match = cur.End.TryMatch(CurText, textOffset); if (match.Success) { FoundSpanEnd(cur, i, match.Length); i += match.Length - 1; return(true); } } if (cur.Exit != null) { RegexMatch match = cur.Exit.TryMatch(CurText, textOffset); if (match.Success) { FoundSpanExit(cur, i, match.Length); i += match.Length - 1; return(true); } } return(false); }
public static void FillMatches(object Group, out SqlInt32 GroupNumber, out SqlString MatchText) { RegexMatch rm = (RegexMatch)Group; GroupNumber = rm.GroupNumber; MatchText = rm.MatchText; }
public bool CreateUser(User u, string loggingId) { try { if (RegexMatch.DoesUserMatch(u)) { _unitOfWork.Users.Create(new Users { AddressTable = new AddressTable { Postcode = u.Postcode, City = u.CityName, Region = u.Region.ToString(), }, Logging_ID = loggingId, Gender = new Repository.DbConnection.Gender { Gender1 = u.Gender.ToString(), }, PayPalMail = u.PayPalMail, FirstName = u.FirstName, LastName = u.LastName, AddressLine = u.AddressLine, Description = u.Description, }); return(true); } return(false); } catch (DuplicateKeyException) { return(false); } }
protected virtual bool ScanSpanEnd(Span cur, ref int i) { if (cur.End != null) { RegexMatch match = cur.End.TryMatch(doc, i); if (match.Success) { OnFoundSpanEnd(cur, i, match.Length); spanStack.Pop(); if (ruleStack.Count > 1) // rulStack[1] is always syntax mode { ruleStack.Pop(); } return(true); } } if (cur.Exit != null) { RegexMatch match = cur.Exit.TryMatch(doc, i); if (match.Success) { spanStack.Pop(); if (ruleStack.Count > 1) // rulStack[1] is always syntax mode { ruleStack.Pop(); } OnFoundSpanExit(cur, i, match.Length); return(true); } } return(false); }
public bool EditUserEmail(User u) { if (RegexMatch.DoesUserEmailMatch(u)) { try { _unitOfWork.Users.UpdateUserMail(new Users { ID = u.ID, AspNetUsers = new AspNetUsers { Email = u.Email, } }); } catch { return(false); } return(true); } else { return(false); } }
private void delayTextChanged(object sender, TextChangedEventArgs e) { if (!RegexMatch.NumericMatch((sender as TextBox).Text)) { (sender as TextBox).Text = RegexReplace.MakeNumeric((sender as TextBox).Text); } }
static Helper() { RegexMatch del = Regex.IsMatch; Interpreter = new Interpreter().SetFunction("RegexMatch", del); }
public StringMatchFilter(bool isFocused = true) { mStringMatch = new StringMatch(Properties, Validate) { IsFocused = isFocused }; mRegexMatch = new RegexMatch(Properties, Validate); }
public static void FillMatches(object Group, out SqlInt32 SNO, out SqlInt32 Position, out SqlString Token, out SqlInt32 Token_Len) { RegexMatch rm = (RegexMatch)Group; SNO = rm.SNO; Position = rm.Position; Token = rm.Token; Token_Len = rm.Token_Len; }
public UriMatchCondition(InputParser inputParser, string input, string pattern, UriMatchPart uriMatchPart, bool ignoreCase, bool negate) { var regex = new Regex( pattern, ignoreCase ? RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase : RegexOptions.CultureInvariant | RegexOptions.Compiled, TimeSpan.FromMilliseconds(1)); Input = inputParser.ParseInputString(input, uriMatchPart); Match = new RegexMatch(regex, negate); }
static void Main(string[] args) { Question1.Test(); EvaluateReversePolishNotation.Test(); MedianTwoSortedArrays.Test(); StringSum.Test(); LongestSubstringWithoutRepeatingChar.Test(); CustomSort.Test(); MergeIntervals.Test(); RegexMatch.Test(); StringToInt.Test(); }
private static RegexMatch CreateRegexMatch(IMatchRule rule, Capture tagMatch, int index, RegexMatch.TagType tagType) { var regexMatch = new RegexMatch { Type = tagType, Value = tagMatch.Value, Index = index, Rule = rule }; return(regexMatch); }
public void RegexMatchExecute() { RegexMatch task = new RegexMatch(); task.BuildEngine = new MockBuild(); task.Input = TaskUtility.StringArrayToItemArray("foo.my.foo.foo.test.o", "foo.my.faa.foo.test.a", "foo.my.fbb.foo.test.b", "foo.my.fcc.foo.test.c", "foo.my.fdd.foo.test.d"); task.Expression = new TaskItem("[a-c]$"); Assert.IsTrue(task.Execute(), "Execute Failed"); Assert.AreEqual(3, task.Output.Length, "Match should have matched three items"); }
private void Button_Click(object sender, RoutedEventArgs e) { var transforms = new List <StringTransform>(); transforms.Add(new LineExtractor()); transforms.Add(new RemoveEmpty()); if (IsRegexProcessingUsed()) { var rxMatch = new RegexMatch(); rxMatch.RegexString = txtRegex.Text.Trim(); if (!string.IsNullOrWhiteSpace(txtRegexGroup.Text)) { var group = txtRegexGroup.Text.Trim(); int groupPosition; var iSgroupNum = int.TryParse(group, out groupPosition); if (iSgroupNum) { rxMatch.GroupPosition = groupPosition; } else { rxMatch.GroupName = group; } } transforms.Add(rxMatch); } transforms.Add(new Trim()); var items = transforms.Transform(txtSource.Text); var perLine = ToInt(txtPerline.Text); if (perLine.HasValue && perLine.Value > 0) { var bins = items.ToBins(perLine.Value); var sb = new StringBuilder(); foreach (var bin in bins) { var text = StringJoin(bin, txtPrefix.Text, txtItemDelimiter.Text, txtSuffix.Text); sb.AppendLine(text); } txtResults.Text = sb.ToString(); } else { var text = StringJoin(items, txtPrefix.Text, txtItemDelimiter.Text, txtSuffix.Text); txtResults.Text = text; } }
private void pageTextChanged(object sender, TextChangedEventArgs e) { if (!RegexMatch.NumericMatch((sender as TextBox).Text)) { (sender as TextBox).Text = RegexReplace.MakeNumeric((sender as TextBox).Text); } // This is janky but it works. I could write an event for this, but there are more important things to do. if ((sender as TextBox).IsReadOnly) { (sender as TextBox).Select((sender as TextBox).Text.Length, 0); } }
public override string Clean() { for (int i = expressions.Count - 1; i >= 0; i--) { RegexMatch variable = GetMatches(expressions[i].value, @"\w+")[0]; input = input.Remove(expressions[i].index + variable.value.Length, expressions[i].value.Length - variable.value.Length); if (expressions[i].value.EndsWith("false")) { input = input.Insert(expressions[i].index, "!"); } } return(input); }
/// <summary> /// Estimates the attempts required to guess the password. /// </summary> /// <param name="match">The match.</param> /// <returns>The guesses estimate.</returns> public static double CalculateGuesses(RegexMatch match) { switch (match.RegexName) { case "recent_year": var yearSpace = Math.Abs(int.Parse(match.Token, CultureInfo.InvariantCulture) - DateMatcher.ReferenceYear); yearSpace = Math.Max(yearSpace, DateGuessesCalculator.MinimumYearSpace); return(yearSpace); default: throw new InvalidOperationException(); } }
private void kryptonButtonOK_Click(object sender, EventArgs e) { int cardType = 0; string dateMatch; modelCardInfo.CardID = kryptonTextBoxCardID.Text.Trim(); modelCardInfo.CardVersion = kryptonTextBoxCardVersion.Text.Trim(); if (int.TryParse(kryptonComboBoxCardType.Text.Trim(), out cardType)) { modelCardInfo.CardType = cardType; } modelCardInfo.CardLevel = kryptonComboBoxCardLevel.Text.Trim(); modelCardInfo.CardPassword = kryptonTextBoxCardPassword.Text.Trim(); dateMatch = kryptonDateTimePickerCardIssueDateTime.Value.ToShortDateString(); if (RegexMatch.IsDate(dateMatch)) { modelCardInfo.CardIssueDateTime = dateMatch; } dateMatch = kryptonDateTimePickerCardValidDateTime.Value.ToShortDateString(); if (RegexMatch.IsDate(dateMatch)) { modelCardInfo.CardValidDateTime = dateMatch; } if (openMode == OpenMode.Add) { if (bllCardInfo.Add(modelCardInfo) == false) { MyMessageBox.MessageBoxOK("Ìí¼Ó¿¨Æ¬Ê§°Ü"); } else { this.Close(); } } else if (openMode == OpenMode.Update) { if (bllCardInfo.Update(modelCardInfo) == false) { MyMessageBox.MessageBoxOK("Ð޸Ŀ¨Æ¬Ê§°Ü"); } else { this.Close(); } } }
public void IsDelegatedToByEstimateGuesses() { var match = new RegexMatch { Token = "1972", RegexName = "recent_year", i = 1, j = 2, }; var result = PasswordScoring.EstimateGuesses(match, "1972"); result.Should().Be(DateMatcher.ReferenceYear - 1972); }
public UriMatchCondition(InputParser inputParser, string input, string pattern, UriMatchPart uriMatchPart, bool ignoreCase, bool negate) { var regexOptions = RegexOptions.CultureInvariant | RegexOptions.Compiled; regexOptions = ignoreCase ? regexOptions | RegexOptions.IgnoreCase : regexOptions; var regex = new Regex( pattern, regexOptions, _regexTimeout ); Input = inputParser.ParseInputString(input, uriMatchPart); Match = new RegexMatch(regex, negate); }
public void Sut_ShouldCoordinateValidation(string strMatch, string regexMatchStr, int expectedMessageBoxCalls) { mSut.Initialize(); StringMatch stringMatch = (StringMatch)mSut.Properties.Single(p => p.GetType() == typeof(StringMatch)); RegexMatch regexMatch = (RegexMatch)mSut.Properties.Single(p => p.GetType() == typeof(RegexMatch)); stringMatch.Value = strMatch; regexMatch.Value = regexMatchStr; stringMatch.TryValidate(mMessageBoxService); mMessageBoxService.Received(expectedMessageBoxCalls).ShowError("Either 'String to Match' or 'Regex to Match' must be specified."); }
protected override bool ScanSpanEnd(Span cur, ref int i) { int textOffset = i - StartOffset; if (cur.End != null && (cur.Rule == "Table" || cur.Rule == "TableHeader")) { if (cur.Rule == "Table") { if (CurText [textOffset] != cur.End.Pattern [0] || CurText.Skip(textOffset + 1).Any(e => e == cur.End.Pattern [0])) { return(false); } } if (cur.Rule == "TableHeader") { if (textOffset != 0 || (!string.IsNullOrWhiteSpace(CurText) && CurText.First(ch => !char.IsWhiteSpace(ch)) == cur.End.Pattern [0])) { return(false); } } FoundSpanEnd(cur, i, 1); return(true); } if (cur.End != null) { RegexMatch match = cur.End.TryMatch(CurText, textOffset); if (match.Success) { FoundSpanEnd(cur, i, match.Length); i += Math.Max(0, match.Length - 1); return(true); } } if (cur.Exit != null) { RegexMatch match = cur.Exit.TryMatch(CurText, textOffset); if (match.Success) { FoundSpanExit(cur, i, match.Length); i += -1; return(true); } } return(false); }
private static Matrix ParseTwoTermProposition(string aExpression, CollectedItems aCollectedItems) { RegexMatch lMatch = TwoTermProposition.Exec(aExpression); Term lSubject = Factory.AllAndOnly( aCollectedItems.AddUnaryPredicate(lMatch[2][0]), lMatch[1].Length > 0); Term lPredicate = Factory.AllAndOnly( aCollectedItems.AddUnaryPredicate(lMatch[5][0]), lMatch[4].Length > 0); bool lModernInterpretation = lMatch[6].Length > 0; return(FormTwoTermProposition(lSubject, lPredicate, lMatch[3][0], lModernInterpretation)); }
private Boolean VerifyNewPassword1() { if (string.IsNullOrEmpty(kryptonTextBoxNewPassword1.Text.Trim())) { labelFailInfo.Text = "密码不能为空"; return(false); } if (RegexMatch.IsManagerPassword(kryptonTextBoxNewPassword1.Text.Trim()) == false) { labelFailInfo.Text = "密码格式无效"; return(false); } return(true); }
private void ResultTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <Object> e) { RegexMatch regexMatch = ResultTreeView.SelectedItem as RegexMatch; if (regexMatch != null) { // A fix to simulate TextBox.HideSelection = False in Windows Forms // Set FocusManager.IsFocusScope = true on TreeView // Then, the following Keyboard.Focus() statements can set logical focus on TextBox, but actual focus on TreeView Keyboard.Focus(ContentTextBox); Keyboard.Focus(ResultTreeView); ContentTextBox.Select(regexMatch.Index, regexMatch.Value.Length); } }
private Boolean VerifyNewPassword2() { if (string.IsNullOrEmpty(kryptonTextBoxNewPassword2.Text.Trim())) { labelFailInfo.Text = "密码不能为空"; WidgetThread.WidgetThread.shakeLable(labelFailInfo); return(false); } if (RegexMatch.IsManagerPassword(kryptonTextBoxNewPassword2.Text.Trim()) == false) { labelFailInfo.Text = "密码格式无效"; WidgetThread.WidgetThread.shakeLable(labelFailInfo); return(false); } return(true); }
public void TestMethod1() { var sut = new RegexMatch(); var streamReader = File.OpenText(@"SIERedovisning.txt"); var content = File.ReadAllText(@"SIERedovisning.txt"); //File.ReadAllText string pattern = @"#VER"; //var content = streamReader.ReadLine(); var match = Regex.Match(content, pattern); sut.CountMatching(content, pattern); if (match.Success) { Debug.WriteLine(content); } }
public static RegexResult Evaluate(RegexQueryBuilder regexQuery) { RegexResult result = new RegexResult(regexQuery); Regex expression = new Regex(regexQuery.Regex, regexQuery.GetOptions()); result.Regex = regexQuery.Regex; result.Replacement = regexQuery.ReplaceText; int searchPos = 0; List<string> groupNames = expression.GetGroupNames().ToList(); Match m = expression.Match(regexQuery.Target, searchPos); SortedList sl = new SortedList(); while (m.Success) { RegexMatch matchResult = new RegexMatch(); groupNames.ForEach(groupName => { var groupMatch = m.Groups[groupName]; foreach (Capture cap in groupMatch.Captures) { RegexCaptureResult groupResult = new RegexCaptureResult() { Index = cap.Index, MatchText = cap.Value, MatchLength = cap.Length, MatchGroupName = groupName }; matchResult.GroupResults.Add(groupResult); } }); result.Matches.Add(matchResult); sl.Add(m.Index, m.Value); m = m.NextMatch(); } result.MatchSortedList = sl; return result; }
bool HasBannedWord(string text, out RegexMatch banWord) { banWord = null; foreach (var word in m_wordBanlist) { if (word.IsMatch(text)) { banWord = word; return true; } } return false; }