# Detecting patterns in a text mass

**URL:** <https://forum.openrefine.org/t/detecting-patterns-in-a-text-mass/1109>\
**Category:** Data cleaning and transformations\
**Created:** [December 10, 2023, 12:46pm UTC](https://forum.openrefine.org/t/detecting-patterns-in-a-text-mass/1109 "2023-12-10T12:46:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Susanna\_Anas](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/susanna_anas/32/728_2.png) [@Susanna\_Anas](https://forum.openrefine.org/u/Susanna_Anas)\
**Post date:** [December 10, 2023, 12:46pm UTC](https://forum.openrefine.org/t/detecting-patterns-in-a-text-mass/1109/1 "2023-12-10T12:46:39Z")

</div>

I have a dataset that I was not able to scrape in a way that it would have been more structured. This resulted in blocks of text, where I can identify patterns for finding the right data. Creating the right regex statement has been challenging.

In the middle of the text block, there could be a line:

"Année d’inclusion à l’inventaire : 2021"

```auto
Which regex statement to use to detect this. I have tried
value.match(/.*Année d'inclusion à l'inventaire(.+)$/)[0]
value.find(/.*Année d'inclusion à l'inventaire(.+)$/)[0]
value.match(/.*|\nAnnée d'inclusion à l'inventaire(.+)$/)[0]
and some other variations

```

I manage to do this with single-line data.

Thank you for your help 🙂

---

<div class="post-metadata">

**Author:** ![b2m](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/b2m/32/139_2.png) [@b2m](https://forum.openrefine.org/u/b2m)\
**Post date:** [December 11, 2023, 7:37am UTC](https://forum.openrefine.org/t/detecting-patterns-in-a-text-mass/1109/2 "2023-12-11T07:37:11Z")

</div>

With [match](https://openrefine.org/docs/manual/grelfunctions#matchs-p) in OpenRefine you have to define a regular expression that matches the complete content. Whereas with [find](https://openrefine.org/docs/manual/grelfunctions#finds-sub-or-p) in OpenRefine you can define a regular expression that matches only on a substring of the content.

As far as I understand you are searching for a line with a variable part in a multi line text statement.  
Usually you could use some "modifiers" to tell the regular expression engine to interpret `$` as the end of a line instead of the end of the whole text.

AFAIK this is not supported with `find` in OpenRefine, but we can either use a more detailed regular expression or the linebreak `\n` instead.

More detailed version:

```javascript
value.find(/Année d.inclusion à l.inventaire : \d+/)[0]

```

Using linebreak:

```javascript
value.find(/Année d.inclusion à l.inventaire[^\n]+/)

```

> **Note:** The OpenRefine forum encodes `'` differently than (my) OpenRefine. So I replaced them with the universal `.` in the regular expressions.

---

<div class="post-metadata">

**Author:** ![Susanna\_Anas](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/susanna_anas/32/728_2.png) [@Susanna\_Anas](https://forum.openrefine.org/u/Susanna_Anas)\
**Post date:** [December 16, 2023, 9:25pm UTC](https://forum.openrefine.org/t/detecting-patterns-in-a-text-mass/1109/3 "2023-12-16T21:25:38Z")

</div>

Thank you for the response, I will try this!
