ParserSearch Method (String, SearchOptions)
Searches a keyword in the document using search options (regular expression, match case, etc.).

Namespace: GroupDocs.Parser
Assembly: GroupDocs.Parser (in GroupDocs.Parser.dll) Version: 20.10.0
Syntax
public IEnumerable<SearchResult> Search(
	string keyword,
	SearchOptions options
)

Parameters

keyword
Type: SystemString
The keyword to search.
options
Type: GroupDocs.Parser.OptionsSearchOptions
The search options.

Return Value

Type: IEnumerableSearchResult
A collection of SearchResult objects; null if search isn't supported.
Remarks
Examples

The following example shows how to search with a regular expression in a document:

C#
// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search with a regular expression with case matching
    IEnumerable<SearchResult> sr = parser.Search("page number: [0-9]+", new SearchOptions(true, false, true));
    // Check if search is supported
    if(sr == null)
    {
        Console.WriteLine("Search isn't supported");
        return;
    }

    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index and found text:
        Console.WriteLine(string.Format("At {0}: {1}", s.Position, s.Text));
    }
}

The following example shows how to search a text on pages:

C#
// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Search a keyword with page numbers
    IEnumerable<SearchResult> sr = parser.Search("line", new SearchOptions(false, false, false, true));
    // Check if search is supported
    if(sr == null)
    {
        Console.WriteLine("Search isn't supported");
        return;
    }

    // Iterate over search results
    foreach(SearchResult s in sr)
    {
        // Print an index, page number and found text:
        Console.WriteLine(string.Format("At {0} (page {1}): {2}", s.Position, s.PageIndex, s.Text));
    }
}
See Also