# Smart Rule wildcards

**URL:** <https://discourse.devontechnologies.com/t/smart-rule-wildcards/60404>\
**Category:** DEVONthink\
**Created:** [December 21, 2020, 11:37am UTC](https://discourse.devontechnologies.com/t/smart-rule-wildcards/60404 "2020-12-21T11:37:39Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [December 19, 2021, 3:38pm UTC](https://discourse.devontechnologies.com/t/smart-rule-wildcards/60404/16 "2021-12-19T15:38:58Z")

</div>

OK, I’m quotng the relevant parts from the documentation.

> Item scanning: The next two actions allow you to scan the name or text of a document and use the results when found. …
> 
> - Scan Name: Scans the name of the file.  
> …  
> The following four parameters are used with the _Scan Name_ and _Scan Text_ actions. …
> 
> - Regular Expression: Items in parentheses are captured; items outside parentheses are ignored. You can specify multiple captures in an expression. Using the captured text in subsequent actions is specified by using backslash, `\`, and the number of the capture, starting at `1`. Note we use Apple’s [NSRegularExpression](https://developer.apple.com/documentation/foundation/nsregularexpression) which supports the [ICU regular expression](http://userguide.icu-project.org/strings/regexp) syntax.

So you have to use a regular expression, because it is not possible otherwise to refer to parts of the match.  
The expression itself should look like this  
`(\d{4})(\d\d)(\d\d)(?:_?\d{4})(-.*)`  
and the replacement like this  
`\1_\2_\3\4`

Explanation: `\d` is RegEx’ish for [0-9], think of “digits”. So we’re first capturing 4, 2, and another 2 digits in the capturing groups (delimited by parenthesis) 1, 2 and 3. Then comes a non-capturing group `(?:...)`. It looks for an optional (`?`) underscore, followed by four digits (`\d{4}`). The last capturing group is `(-.*)`, i.e. the “-Name” part in your example. This group is # 4, since non-capturing groups are not counted.

In the replacement part, you simply string together the capturing groups 1 through 4 with the underscores you want.

Since the rule only matches the file names you described, it should do what you want. Please test first with a copies! And adjust the rule accordingly if the part after the date is not four digits…

---

_[View the full topic](https://discourse.devontechnologies.com/t/smart-rule-wildcards/60404)._
