# Which RegEx syntax does Gramps use?

**URL:** <https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278>\
**Category:** Help\
**Tags:** regular-expression\
**Created:** [February 18, 2022, 11:21am UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278 "2022-02-18T11:21:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 18, 2022, 11:21am UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/1 "2022-02-18T11:21:22Z")

</div>

There are evidently a variety of [standard syntaxes for RegEx](https://wikipedia.org/wiki/Regular_expression#Standards). Which [Regular Expressions](https://gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual_-_Filters#Regular_Expressions) standard (and possibly , which sub-dialect) was implemented in Gramps?

I’m guessing that it is the POSIX rather than Perl. But there are 3 compliance levels of the IEEE POSIX syntax: **BRE** (Basic Regular Expressions), **ERE** (Extended Regular Expressions), and the _deprecated_ **SRE** (Simple Regular Expressions)

If a person is looking for tutorials and cheatsheats on the net, it would be helpful to be certain of which they should be seeking.

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [February 18, 2022, 12:53pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/2 "2022-02-18T12:53:26Z")

</div>

Where did you found the SRE is deprecated ?  
The differences between all these syntaxes are very minimal (escape some characters)

> [@emyoulation](#):
>
> If a person is looking for tutorials and cheatsheats on the net, it would be helpful to be certain of which they should be seeking.

For gramps we don’t need to know the differences.

Perhaps you don’t understand how it works.  
I use regexp every days with gramps, sed, grep and found no differences in a standard usage.

You have the resonse in the re.py file distributed by python

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [February 18, 2022, 12:58pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/3 "2022-02-18T12:58:20Z")

</div>

> [@emyoulation](#):
>
> If a person is looking for tutorials

You have the following page in gramps documentation:  
[https://gramps-project.org/wiki/index.php/Gramps\_5.1\_Wiki\_Manual\_-\_Filters](https://gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual_-_Filters)

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 18, 2022, 1:55pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/4 "2022-02-18T13:55:31Z")

</div>

> [@SNoiraud](#):
>
> Where did you found the SRE is deprecated

The Wikipedia page. It states SRE is deprecated in favor of BRE.

> [@SNoiraud](#):
>
> You have the following page in gramps documentation

There are entire Books & Websites dedicated to mastering RegEx.

Adding syntax tutorials to the [Gramps wiki](https://gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual#Table_of_Contents) is reinventing the wheel.

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [February 18, 2022, 1:57pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/5 "2022-02-18T13:57:53Z")

</div>

> [@emyoulation](#):
>
> Adding syntax tutorials to the [Gramps wiki](https://gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual#Table_of_Contents) is reinventing the wheel.

So, we don’t need a wiki anymore.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 18, 2022, 2:05pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/6 "2022-02-18T14:05:29Z")

</div>

No. It just doesn’t make sense for the syntax RegEx. For the general syntax tutorial, we can suggest an appropiate external webpage in the See Also section. (We need a Gramps RegEx user to suggest a good external webpage with the right dialect of RegEx!)

Tutorials on the application of RegEx for Gramps data makes sense.

But adding tutorials on RegEx syntax would be like adding wiki tutorial on your OS or learning Python. These are already done better elsewhere. The wiki should only address how to they relate in an unusual way to Gramps.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 18, 2022, 2:09pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/7 "2022-02-18T14:09:17Z")

</div>

> [@SNoiraud](#):
>
> Perhaps you don’t understand how it works.  
> I use regexp every days with gramps, sed, grep and found no differences in a standard usage.

If there is no difference, why are there different specifications that are still being maintained separately?

---

<div class="post-metadata">

**Author:** ![prculley](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/prculley/32/41_2.png) [@prculley](https://gramps.discourse.group/u/prculley)\
**Post date:** [February 18, 2022, 4:12pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/8 "2022-02-18T16:12:44Z")

</div>

Gramps uses the Python version of regular expressions [re — Regular expression operations — Python 3.10.2 documentation](https://docs.python.org/3/library/re.html)

I could not find any reference to suggest that it follows any of the POSIX levels, although for the usage of our filters I suspect that this doesn’t matter.

I think that for the vast majority of likely re used in Gramps, the relatively minor variations in syntax just doesn’t matter. I suppose that a very advanced user might be able to find some expression where it does; but I also suspect that user could read the Python docs to get the details.

Note in the documentation that the Python version of re has changed over time, usually in a backward compatible fashion. So the actual syntax of Gramps would be that of the version of Python that you have installed to run Gramps.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 28, 2022, 2:44pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/9 "2022-02-28T14:44:55Z")

</div>

I cannot help that the term “RegEx” always reminds me of a [2 second video clip](https://getyarn.io/yarn-clip/5f6ea021-56bb-4887-8616-50ad0e6d0287) from the “Wolf In the Fold” Star Trek (TOS) episode.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [June 23, 2022, 1:56pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/12 "2022-06-23T13:56:33Z")

</div>

> [@prculley](#):
>
> Gramps uses the Python version of regular expressions [re — Regular expression operations — Python 3.10.2 documentation](https://docs.python.org/3/library/re.html)

in the documentation you cited, the following note is in the opening section of the docs.

> See also
> 
> The third-party [regex](https://pypi.org/project/regex/) module, which has an API compatible with the standard library [`re`](https://docs.python.org/3/library/re.html#module-re) module, but offers additional functionality and a more thorough Unicode support.

Given that Gramps is heavy in Unicode use (and the recent inquiry about Case Sensitivity not being controllable), is that third-party **regex** more appropriate for Gramps than the standard library **re** module?

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [April 25, 2024, 5:25pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/13 "2024-04-25T17:25:15Z")

</div>

If the RegEx syntax is variable… based on the Python version in use, then RegEx “help” that has a dynamic URL would be useful.

One assumes that the basics will be fairly static. But possibly still very un-intuitive and needing documentation.

For example, I just needed to search for name prefixes that were not blank. It is _ **very** _ unlikely that I would intuitively know that the string `(.|\s)*\S(.|\s)` is a usable RegEx expression to search for a non-NULL string.

 ![image](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/d/d4f2e9c6223bc061b22c8e0386d775d5df1d22c0.png)

---

<div class="post-metadata">

**Author:** ![RenTheRoot](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/rentheroot/32/4538_2.png) [@RenTheRoot](https://gramps.discourse.group/u/RenTheRoot)\
**Post date:** [April 25, 2024, 8:49pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/14 "2024-04-25T20:49:00Z")

</div>

> [@emyoulation](#):
>
> If the RegEx syntax is variable… based on the Python version in use, then RegEx “help” that has a dynamic URL would be useful.

This is my favorite regex debugger which I use all the time (It is necessary for some cybersecurity competitions I do): [https://regex101.com](https://regex101.com)

Perhaps a help page on using such a debugger would be useful. We can also establish a standard tag that can be used to label regex commands created by gramps users so they can be searched in the “community patterns” and occasionally grab particularly useful examples and add them to the wiki.

---

<div class="post-metadata">

**Author:** ![RenTheRoot](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/rentheroot/32/4538_2.png) [@RenTheRoot](https://gramps.discourse.group/u/RenTheRoot)\
**Post date:** [April 25, 2024, 8:58pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/15 "2024-04-25T20:58:07Z")

</div>

> [@RenTheRoot](#):
>
> Perhaps a help page on using such a debugger would be useful.

I’d actually be willing to work on this. I enjoy writing documentation and could probably put something together.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [April 25, 2024, 9:13pm UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/16 "2024-04-25T21:13:41Z")

</div>

> [@RenTheRoot](#):
>
> I’d actually be willing to work on this.

I would be roasted on a pyre if I encouraged your splitting attention from development to User Documentation!!!  
The [RegEx entry](https://gramps-project.org/wiki/index.php/Gramps_Glossary#regex) in the [Gramps Glossary](https://www.gramps-project.org/wiki/index.php/Gramps_Glossary) has an internal link (to an embryonic descriptions of the expression syntax) and an external link (to this Discourse discussion thread) where the documentation can evolve.

But I _ **do** _ advocate GUI hotlinking every incidence of a RegEx option. That link would be to “help” in composing RegEx expressions. Whether that “help” is: hotlinking to the **Gramps&nbsp;Glossary** Entry, or; the popping up of a RegEx composition/debugging tool; is a design choice… and beyond my ken.

---

<div class="post-metadata">

**Author:** ![RenTheRoot](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/rentheroot/32/4538_2.png) [@RenTheRoot](https://gramps.discourse.group/u/RenTheRoot)\
**Post date:** [April 26, 2024, 12:01am UTC](https://gramps.discourse.group/t/which-regex-syntax-does-gramps-use/2278/17 "2024-04-26T00:01:19Z")

</div>

> [@emyoulation](#):
>
> I would be roasted on a pyre if I encouraged your splitting attention from development to User Documentation

Ha! I look at it more as an opportunity to gain a deeper understanding of some of the Gramps features for future development purposes. It also looks like I might be able to finish multiple projects over the course of the summer.
