Skip to content

Commit

Permalink
fix non-alphanumeric error
Browse files Browse the repository at this point in the history
removes any non-alphanumeric characters using regex before search
else will crash when text contains non-alphanumeric characters
  • Loading branch information
sengiv authored Aug 30, 2022
1 parent 2938823 commit 1b80ea0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions WuManber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace WuManberNet
{
Expand Down Expand Up @@ -159,8 +160,12 @@ public void Initialize(List<WordMatch> patterns, bool bCaseSensitive = false, bo
m_bInitialized = true;
}

public IEnumerable<WordMatch> Search(string text)
{
public IEnumerable<WordMatch> Search(string rawText)
{
//remove any non-alphanumeric characters
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
var text = rgx.Replace(rawText, "");

if (m_bInitialized)
{
var ix = m - 1; // start off by matching end of largest common pattern
Expand Down

0 comments on commit 1b80ea0

Please sign in to comment.