Gravatar for erik.nummela@safe.com

Question by enummela, Jun 11, 2018 7:40 PM

Source Filter JSON Does Not Accept Regular Expressions

I'm trying to add an exclusion filter to a sitemap source to prevent certain pages from being indexed. So far I haven't been able to create patterns using regular expressions. Whenever I create the pattern using a patternType value of Regex or RegularExpression (as per different pages in the docs) and save the JSON the patternType property disappears from the object it's added to. At no point is an error message displayed.

Has someone successfully created source filters using regular expressions and if so could they offer some guidance or a JSON snippet?

    "addressPatterns": [
      {
        "expression": "*",
        "patternType": "Wildcard",
        "allowed": true
      },
      {
        "expression": "^.*Default\\\.htm$",
    "patternType": "RegularExpression",
        "allowed": false
      },
      {
        "expression": "^.*Default\\\.htm$",
    "patternType": "Regex",
        "allowed": false
      }
    ]

becomes

    "addressPatterns": [
      {
        "expression": "",
        "patternType": "Wildcard",
        "allowed": true
      },
      {
        "expression": "^.Default\.htm$",
        "allowed": false
      },
      {
        "expression": "^.*Default\.htm$",
        "allowed": false
      }
    ]

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jun 11, 2018 7:55 PM

`^.*Default\.htm$` should be `^.*Default\\.htm$`.

`patternType` should be `RegEx`.

To find it, I went in the UI to apply the RegExp and then looked at the resulting JSON configuration of the source.

Gravatar for erik.nummela@safe.com

Comment by enummela, Jun 11, 2018 8:04 PM

Correct, I actually wrote `^.*Default\\.htm$` in my question but the code block must be interpreting one of the slashes as an escape character. I've updated my question to fix the formatting. However, the problem still persists.

Thanks for the reply Jean-François.

Gravatar for erik.nummela@safe.com

Comment by enummela, Jun 11, 2018 8:05 PM

I see your updated answer solves my problem. I will use `RegEx` as the patternType.

Thanks again!

Ask a question