Finding the matched text in a regex search

Posted by: jerrad.elmore on 21 March 2022, 5:00 am EST

  • Posted 21 March 2022, 5:00 am EST

    I am using the GcPdfDocument.FindText method with a regular expression search parameter. This method correctly finds matching text, but the result doesn't seem to include a property that shows the text that was actually matched. It has a NearText property, but it includes additional text "near" the found text (hence the name NearText, I guess). Is the exact matched text intentionally not returned for some reason? I guess I could use the .NET regex function on the NearText property to extract the exact text, but that feels like an unneccessary step. Am I missing something? Thanks.
  • Replied 21 March 2022, 9:31 pm EST

    Hello,

    Can you please share your stripped-down sample to show what you are doing and how?
    It will help us to replicate the issue at our end and assist you accordingly.

    Regards,
    Prabhat Sharma.
  • Replied 22 March 2022, 2:01 am EST

    After looking around a little more, I see the TextMapFragment property that appears to show the positions of the matched text within the NearText property, but it doesn't always seem to be the correct positions. I have attached a small project that hopefully demonstrates the issue.
    IFindTextTest.zip
  • Replied 22 March 2022, 8:49 pm EST

    Hello,

    Thank you for the attached sample.
    We are discussing this issue with the developers and will let you know the updates soon.
    [Internal Tracking ID: DOC-4133]

    Regards,
    Prabhat Sharma.
  • Replied 3 April 2022, 10:45 pm EST

    Hello,

    The requirement is not clear to the developers with your given comments. They have modified the sample, and PositionInNearText has correct value, please go through it and let me know if it works.


    Regards,
    Prabhat Sharma.
    DOC-4133.zip
  • Marked as Answer

    Replied 6 April 2022, 3:57 am EST

    Ok, so to extract the found text, I would need to do
    text.NearText.Substring(text.PositionInNearText, text.TextMapFragment[0].Length)


    It seems confusing to me that FoundPosition has a property for the start position, but not the length (I have to go into the TextMapFragment to get the length). Anyway, thanks for the help.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels