Regex Test \ Exception: parsing "Regex\s{0,1}Test\s{0,1}\" - Illegal \ at end of pattern.
Regex Test ^ phrase not found.
Regex Test | Exception: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The code to demonstrate/recreate these issues is below:
- Code: Select all
[TestClass]
public class UnitTest1
{
private readonly string[] strShortList =
{
@"Regex Test \",
@"Regex Test ^",
@"Regex Test |",
@"Regex Test\",
@"Regex Test^",
@"Regex Test|",
@"\Regex Test",
@"^Regex Test",
@"|Regex Test"
};
[TestMethod]
public void TestMethod1()
{
string strFileName = @".\Special Characters.pdf";
Spire.Pdf.PdfDocument pdf = new PdfDocument(strFileName);
TextFindParameter tfp = new TextFindParameter();
tfp |= TextFindParameter.CrossLine;
//tfp |= TextFindParameter.WholeWord;
foreach (string strCurrent in strShortList)
{
try
{
PdfTextFind[] pdfResult = pdf.Pages[0].FindText(strCurrent, tfp).Finds;
Console.WriteLine(pdfResult.Length > 0 ? "{0} phrase Found" : "{0} phrase not found.", strCurrent);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception: {1}", strCurrent, e.Message);
}
}
pdf.Dispose();
}
}