# InsightIDR LEQL to RegEx Help Needed

**URL:** <https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868>\
**Category:** Alerts\
**Tags:** InsightIDR\
**Created:** [February 7, 2022, 12:33pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868 "2022-02-07T12:33:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nowel](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/n/a4c791/32.png) [@nowel](https://discuss.rapid7.com/u/nowel)\
**Post date:** [February 7, 2022, 12:33pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/1 "2022-02-07T12:33:41Z")

</div>

Hi!

I tried to create a Dashboard Card and a custom alert notification for my intended use case just that when I try to use my query from the Card in the custom alert it doesn’t actually accept it. And I realized that what am trying to get a custom alert would need a RegEx equivalent. Problem is am really a beginner in RegEx. Would anyone willing to help me on this?

Goal: Create a Card representation and a corresponding notification whenever a user shares a file outside of the listed domains in Office365

Here’s my Card Query:  
where(source\_user CONTAINS-ANY [@domain1.net.ph, @domain1\_1.net.ph, @domain2.com.ph, @domain2\_1.com.ph, @domain3.ph, @domain4.com] AND source\_json.TargetUserOrGroupType=“Guest” AND source\_json.TargetUserOrGroupType NOT IN [@domain1.net.ph, @domain1\_1.net.ph, @domain2.com.ph, @domain2\_1.com.ph, @domain3.ph, @domain4.com]) groupby(source\_user)

Custom Alert Goal: To create a notification whenever there is a positive match of the above.

Initial Attempt: As I really suck at RegEx, I tried going around the LEQL and made the below which actually doesn’t return an error in the Priority and Trigger under Custom Alert Setup.

(source\_user CONTAIN @domain1.net.ph)  
AND source\_json.TargetUserOrGroupType=“Guest”  
AND (source\_json.TargetUserOrGroupType NOT @domain1.net.ph OR  
source\_json.TargetUserOrGroupType NOT @domain1\_1.net.ph OR  
source\_json.TargetUserOrGroupType NOT @domain2.com.ph OR source\_json.TargetUserOrGroupType NOT @domain2\_1.com.ph OR source\_json.TargetUserOrGroupType NOT @domain3.ph OR  
source\_json.TargetUserOrGroupType NOT @domain4.com)

If I go with this, then I need to create an entry for each source\_user=domain one by one. Not sure if its the best way though as I think the regex should be one.

Any help or advise would be very much appreciated.

---

<div class="post-metadata">

**Author:** ![alexey\_shulga](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alexey\_shulga](https://discuss.rapid7.com/u/alexey_shulga)\
**Post date:** [February 7, 2022, 12:50pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/2 "2022-02-07T12:50:45Z")

</div>

Hello nowel,  
Thanks for the question!

Let me follow up with your approach without complex regex, although I must note that we shouldn’t use CONTAINS keyword in Custom Alerts  
Also ensure correct escaping of symbols in regex.

```auto
where(
  (
       source_user = /@domain1\.net\.ph/
    OR source_user = /@domain1_1\.net\.ph/
    OR source_user = /@domain2\.com\.ph/
    OR source_user = /@domain2_1\.com\.ph/
    OR source_user = /@domain3\.ph/ 
    OR source_user = /@domain4\.com/
  )
  AND source_json.TargetUserOrGroupType="Guest" AND NOT
  (
       source_json.TargetUserOrGroupType = @domain1.net.ph
    OR source_json.TargetUserOrGroupType = @domain1_1.net.ph
    OR source_json.TargetUserOrGroupType = @domain2.com.ph
    OR source_json.TargetUserOrGroupType = @domain2_1.com.ph
    OR source_json.TargetUserOrGroupType = @domain3.ph
    OR source_json.TargetUserOrGroupType = @domain4.com
  )
)
groupby(source_user)

```

Could you pls take a look if all the values in key-value conditions are correct?  
Thanks,  
Alexey

---

<div class="post-metadata">

**Author:** ![SDavis](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/sdavis/32/843_2.png) [@SDavis](https://discuss.rapid7.com/u/SDavis)\
**Post date:** [February 7, 2022, 1:44pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/3 "2022-02-07T13:44:18Z")

</div>

Thanks @alexey_shulga!!

@nowel As long as the keywords do in fact match up with what your logs show, you could test the following in your custom pattern detection and see if any matches appear:

`where((source_user=/.*\@domain1\.net\.ph|.*\@domain1_1\.net\.ph|.*\@domain2\.com\.ph|.*\@domain2_1\.com\.ph|.*\@domain3\.ph|.*\@domain4\.com/i) AND source_json.TargetUserOrGroupType=“Guest” AND source_json.TargetUserOrGroupType!=/.*\@domain1\.net\.ph|.*\@domain1_1\.net\.ph|.*\@domain2\.com\.ph|.*\@domain2_1\.com\.ph|.*\@domain3\.ph|.*\@domain4\.com/i)groupby(source_user)`

---

<div class="post-metadata">

**Author:** ![david\_smith](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@david\_smith](https://discuss.rapid7.com/u/david_smith)\
**Post date:** [February 7, 2022, 10:56pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/4 "2022-02-07T22:56:06Z")

</div>

I also wanted to share that we are actively working on bringing the full suite of LEQL keywords to custom alerts. We have a tentative plan to deliver this in the coming month. For now regex is required, but once we release the new LEQL custom alerts anything you can do in search in terms of keywords will be available in alerting.

Note: Groupby alerting is not included in this upcoming, we have other plans to address the use case of more complex custom alerting in the future.

David

---

<div class="post-metadata">

**Author:** ![nowel](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/n/a4c791/32.png) [@nowel](https://discuss.rapid7.com/u/nowel)\
**Post date:** [February 8, 2022, 3:47am UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/5 "2022-02-08T03:47:31Z")

</div>

Thanks a lot! @alexey_shulga @david_smith

Will do a run on this one based on your suggestions.

@david_smith  
Thanks for giving out that info on the enhancement, hope this would come out the soonest.

---

<div class="post-metadata">

**Author:** ![rford](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/r/cdc98d/32.png) [@rford](https://discuss.rapid7.com/u/rford)\
**Post date:** [February 9, 2022, 8:49pm UTC](https://discuss.rapid7.com/t/insightidr-leql-to-regex-help-needed/9868/6 "2022-02-09T20:49:23Z")

</div>

One other tool I’d recommend utilizing if you want some help with regex queries is [regex101.com](http://regex101.com) . You plop it in the text you’re looking to match against and then can fine tune your regex.
