The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Regular Expression - M-FIles Text Analytics

Hi,

I'm not a developer, but I'm trying to configure the M-Files Text Analytics. :). In a document (Contract) is a text Contract No. After that text is a number. A want to add that number to a property definition. So, basically, I want to add a value after the "Contract No." and before the first space.

I've been searching on the internet for the last 3 hours, but I have nothing to show Disappointed

Any help would be appreciated.

Below is the script from the MF Text Analytics:

{
    "targetName": "ContractNo",
    "documentContentPattern": "THIS IS WHERE I WANT TO PUT THE REGULAR EXPRESSION",
    "comment": "PArtnerjeva številka pogodbe",
    "enabled": true,
    "forceSetValue": true
}

BTW, is that even doable in MF Text Analytics?

Best, Uros

  • Hi Uros,

    It is certainly doable. Something like this should work for you:

    "(\\bContract\\sNo\\.\\s*(?<value>\\d{5}\\b))",

    The {5} indicates the number of digits. Change it to fit your situation or replace '{5}' with '+' , if Contract No. does not have a fixed number of digits.

    Checkout http://www.ultrapico.com/expresso.htm for a tool to test your expressions against real world text samples. Remember that you need to double each backslash in M-Files because the expression is placed in JSON code. There are plenty of websites with explanations on regex, so folks like us can learn the basics relatively fast, if we set our mind to it Relaxed

    RB, Karl

  • Karl, thx a lot. The beer is on me if we ever meet Slight smile

    "Remember that you need to double each backslash in M-Files because the expression is placed in JSON code. " THX for that explanation. Now I know why so many cases were marked as errors.

    Best, Uros

  • I have one more question. I want to also extract date from the document. I was playing with your code. It's working if I add the value to a text filed. It's not working if I try to add the value into date field. I was searching on the internet, tried with a date validation scripts....

    The date format is dd. mm. yyyy. Below is an example of my regular expression. I want to add the date after the text "Ljubljana, ".

    (\\bLjubljana\\,\\s*(?<value>\\d{2}\\.\\s\\d{2}\\.\\s\\d{4}\\b))

    Best, Uros

  • The primary trick on dates is to add a "normalizeas" line. You should nomalize to the locale used on your M-files server.

    Here is a setting, that I use a lot and that will recognize a wide range of date formats.

    {
        "targetName": "Date_dd-mm-yyyy",
        "documentContentPattern": "(?<value>(\\b(?<Day>([0-3]?[0-9]))(?:[-/\\.])(?<Month>([0-1]?[0-9]))(?:[-/\\.])(?<Year>([0-9]{2,4}))\\b)|(\\b(?<Year>([0-9]{2,4}))(?:[-/\\.])(?<Month>([0-1]?[0-9]))(?:[-/\\.])(?<Day>([0-3]?[0-9]))\\b))",
        "comment": "Date in (d)d-(m)m-(yy)yy short or long format",
        "normalizeAs": "Date(da-DK)",
        "enabled": true
    }

  • The Text Analytics configuration guide has further information on the normalizeAs option on pages 12-14 under "Converting text value metadata suggestions to another data type".

  • OMG... how easy it can be if you have the last version of the documentation Slight smile

    Big THANK YOU to both of you and it looks like I'll have to buy two beers ;)

    Kind regards, Uros