Okta Group Attribute Statement Regex Filter - regex

I wrote the regex below in Okta group attribute statement filter which returns all the groups a user is part of based on the group naming convention.
*H_DAM_.*|.*H_TOOLS_.*|.*H_ASSOCIATES.*
Sample output for a particular user:
H_DAM_TESTER
CDG_H_DAM_ADMIN
CDG_H_ASSOCIATES
If I want Okta to remove "CDG_", so the output group names would start with H_ only, what would be the correct syntax for my regex?

Related

Regex Group Name prefix multiple options

I'm performing regex extraction for parsing logs for our SIEM. I'm working with PCRE2.
In those logs, I have this problem: I have to extract a field that can be preceded by multiple options and I want use only one group name.
Let me be clearer with an example.
The SSH connection can appear in our log with this form:
UserType=SSH,
And I know that a simple regex expression to catch this is:
UserType=(?<app>.*?),
But, at the same time, SSH can appear with another "prefix":
ACCESS TYPE:SSH;
that can be captured with:
ACCESS\sTYPE:(?<app>.*?);
Now, because the logical field is the same (SSH protocol) and I want map it in every case under group name "app", is there a way to put the previous values in OR and use the same group name?
The desiderd final result is something like:
(UserType=) OR (ACCESS TYPE:) <field_value_here>
You can use
(?:UserType=|ACCESS\sTYPE:)(?<app>[^,;]+)
See the regex demo. Details:
(?:UserType=|ACCESS\sTYPE:) - either UserType= or ACCESS + whitespace + TYPE:
(?<app>[^,;]+) - Group "app": one or more chars other than , and ;.

How to use Postgres Regex Replace with a capture group

As the title presents above I am trying to reference a capture groups for a regex replace in a postgres query. I have read that the regex_replace does not support using regex capture groups. The regex I am using is
r"(?:[\s\(\)\=\)\,])(username)(?:[\s\(\)\=\)\,])?"gm
The above regex almost does what I need it to but I need to find out how to only allow a match if the capture groups also capture something. There is no situation where a "username" should be matched if it just so happens to be a substring of a word. By ensuring its surrounded by one of the above I can much more confidently ensure its a username.
An example application of the regex would be something like this in postgres (of course I would be doing an update vs a select):
select *, REGEXP_REPLACE(reqcontent,'(?:[\s\(\)\=\)\,])(username)(?:[\s\(\)\=\)\,])?' ,'NEW-VALUE', 'gm') from table where column like '%username%' limit 100;
If there is any more context that can be provided please let me know. I have also found similar posts (postgresql regexp_replace: how to replace captured group with evaluated expression (adding an integer value to capture group)) but that talks more about splicing in values back in and I don't think quite answers my question.
More context and example value(s) for regex work against. The below text may look familiar these are JQL filters in Jira. We are looking to update our usernames and all their occurrences in the table that contains the filter. Below is a few examples of filters. We originally were just doing a find a replace but that doesn't work because we have some usernames that are only two characters and it was matching on non usernames (e.g je (username) would place a new value in where the word project is found which completely malforms the JQL/String resulting in something like proNEW-VALUEct = balh blah)
type = bug AND status not in (Closed, Executed) AND assignee in (test, username)
assignee=username
assignee = username
Definition of Answered:
Regex that will only match on a 'username' if its surrounded by one of the specials
A way to regex/replace that username in a postgres query.
Capturing groups are used to keep the important bits of information matched with a regex.
Use either capturing groups around the string parts you want to stay in the result and use their placeholders in the replacement:
REGEXP_REPLACE(reqcontent,'([\s\(\)\=\)\,])username([\s\(\)\=\)\,])?' ,'\1NEW-VALUE\2', 'gm')
Or use lookarounds:
REGEXP_REPLACE(reqcontent,'(?<=[\s\(\)\=\)\,])(username)(?=[\s\(\)\=\)\,])?' ,'NEW-VALUE', 'gm')
Or, in this case, use word boundaries to ensure you only replace a word when inside special characters:
REGEXP_REPLACE(reqcontent,'\yusername\y' ,'NEW-VALUE', 'g')

CloudWatch Insights - Group logs by url with unique ids removed

I'm looking to use CloudWatch Logs Insights to group logs by a request url field, however the url can contain 0-2 unique numerical identifiers that I'd like to be ignored when doing the grouping.
Some examples of urls:
/dev/user
/dev/user/123
/dev/user/123/inventory/4
/dev/server/3/statistics
The groups would look something like:
/dev/user
/dev/user/
/dev/user//inventory/
/dev/server//statistics
I have something quite close to what I need which extracts the section of the url in front of the first optional identifier and the section between the first identifier and the second identifier and concatenates the two, but it isn't totally reliable. This is where I'm at currently, #message is valid json which containers an 'endpoint' field that looks like one of the urls above:
fields #message | parse endpoint /(\bdev)\/(?<#prefix>[^0-9]+)(?:[0-9]+)(?<#suffix>[^0-9]+)/ | stats count(*) by #prefix
While this query will work with endpoints like '/dev/accounts/1' it ignores endpoints like '/dev/accounts' as it doesn't have all of the components the regex is looking for, which means I'm missing a lot of results.
If there are 0-2 numerical identifiers that you want to remove, you could match the first and optionally match the second number and use 2 capturing groups to capture what you want to keep.
In the replacement use the 2 capturing groups $1$2
^(.*?\/)\d+(?:(.*?\/)\d+\b)?
Regex demo
Looks like I can use question marks outside of capture groups to mark those groups as optional, which has resolved the last issue I was having.
Regex demo

Google Analytics regex doesn't replace multiple instances of an expression

I want to setup a filter and replace on URI in my Google Analytics account and I want to filter "/" sperated values from URI:
This is a sample list of URIs:
/clients/1282/buildings/4490
/clients/1362/buildings/8915/systems
/clients/1362/buildings/8915/systems/manage-rules/configure-rules
/clients/1282/buildings/4490/insights/rule-templates
/clients/1167/buildings/4126/insights/4126.10100.PG1-Program_Data
this is the regex I apply the moment but it captures only the first instance and it doesn't work for the last URI (mix of text and numbers)
(\/)\d+
results of the current state is :
/clients/1282/buildings/4490
/clients/1362/buildings/8915/systems
/clients/1362/buildings/8915/systems/manage-rules/configure-rules
/clients/1282/buildings/4490/insights/rule-templates
/clients/1167/buildings/4126/insights/4126.10100.PG1-Program_Data
expected result
/clients/buildings/
/clients/buildings/systems
/clients/buildings/systems/manage-rules/configure-rules
/clients/buildings/insights/rule-templates
/clients/buildings/insights/
Create one Search and Replace for the first group and another for the second group.

Boolean regex AND with multiple capture groups in Javascript not working

I'm attempting to capture 3 mandatory elements of a URL with multiple capture groups in Javascript Regex, but for the life of me I can't get it to work. Does anyone know what I'm doing wrong?
https://bobsfurniture.com/chairs/COZRdyga141uWgV5w/purchase/?itemIds=qUUWmD7eRaCz9wnJEGLZQQ
I'm trying to capture the domain, the product category (chairs), and the purchase. This is my capture grouping:
(?=.*bobsfurniture)(?=.*chairs)(?=.*purchase)