I'm trying to match the text value_to_match when preceeded by a line "attribute": "type" and preceeded (at some point) by a "marketTypeId": 123456789 in Intellij regex search.
In the following text the search should match value_to_match only.
{
"marketTypeId": 123456789,
"description": "Market description",
"periodType": "MATCH",
"periodInstance": 1,
"feedMappingData": [
{
"outcomeIdFeedcodeMap": {
"2": "123456789001",
"1": "123456789002"
},
"conditions": [
{
"element": "Market",
"attribute": "type",
"condition": "EQUALS",
"value": "value_to_match"
},
{
"element": "Market",
"attribute": "traded_pre_match",
"condition": "EQUALS",
"value": "true"
}
]
},
{
"marketTypeId": 12121212,
"description": "Market description",
"periodType": "MATCH",
"periodInstance": 1,
"feedMappingData": [
{
"outcomeIdFeedcodeMap": {
"2": "12121212001",
"1": "12121212002"
},
"conditions": [
{
"element": "Market",
"attribute": "type",
"condition": "EQUALS",
"value": "value_NOT_to_match"
},
{
"element": "Market",
"attribute": "traded_pre_match",
"condition": "EQUALS",
"value": "true"
}
]
},
I've been trying to use lookbehind with the conditions but it seems Intellij regex search does not support infinite repetition inside lookbehind.
Is there any workaround for situations like this?
Using Intellij and positive lookbehind
The regex used in Intellij:
(?s)(?<="marketTypeId":\s123456789,.{1,500}"attribute":\s"type",.{1,100}"value":\s")value_to_match(?=")
Note:
Dotall mode can also be enabled via the embedded flag expression (?s)
Read more about this flag expression and regex lookarounds in reference:
https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html
Used Intellij version 2020.2
Picture of Intellij and match:
More can be read about Intellij and matching here:
Is there a way with Regex to grab the first word and replace a quoted section?
Related
I'm using the same example from examples/schemavalidator.cpp.
My schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "SampleMessage",
"properties": {
"id": {
"type": "string"
},
"regexfield": {
"type": "string",
"pattern": "^[\\x00-\\x7F]*$"
},
"status": {
"type": "string",
"enum": [
"VALID",
"INVALID"
]
}
},
"required": [
"regexfield",
"status"
]
}
My message;
{
"id": "w10ooe",
"regexfield": "w10ooe¼",
"status": "VALID"
}
Expected result:
validation fail for pattern
Actual result
Input JSON is valid.
As you can see, the pattern is for validating if the regexfield contains only ASCII characters. However, the validation returns successful even when the field has a non-ascii value. The same regex gives expected result when checking with regex101.com. can you please explain how to address this issue and a workaround?
The default regex engine does not support character escapes of the form \xXX (note the lack of a x option in this switch).
You can switch to std::regex (which does support this) by setting both of the following preprocessor symbols:
RAPIDJSON_SCHEMA_USE_INTERNALREGEX=0
RAPIDJSON_SCHEMA_USE_STDREGEX=1
You can either #define these macros at the top of your file or set them as a preprocessor flag in your build system (-D...)
I have the following list:
"domain": "example1.com"
"type": "web"
"domain": "example2.com"
"type": "web"
"domain": "example3.com"
"type": "mobile"
"domain": "example4.com"
"type": "web"
I want to use regex to search for "type": "mobile" and mark the line above it: "domain": "example3.com"
Then in Gaza NOTEPAD++ I can perform replace on these two lines together:
"domain": "example3.com"
"type": "mobile".This will be the result:
"domain": "example1.com"
"type": "web"
"domain": "example2.com"
"type": "web"
"domain": "example4.com"
"type": "web"
I tried using the following regex but the \n doesn't work
"domain:*".*\n"type": "web"
The : should be after the " and you want to match mobile instead of type
"domain":.*\R"type": "mobile"\R?
Regex demo
I have a situation where I need to filter out certain events using eventpatterns in eventbridge.
I want to run the rule for all events except those where username starts with abc or xyz.
I have tried below 2 syntax but none worked :
"userIdentity": {
"sessionContext": {
"sessionIssuer": {
"userName": [
{
"anything-but": {
"prefix": [
"abc-",
"xyz-"
]
}
}
]
}
}
}
"userIdentity": {
"sessionContext": {
"sessionIssuer": {
"userName": [
{
"anything-but": [{
"prefix": "abc-",
"prefix": "xyz-"
}]
}
]
}
}
}
Getting following error on saving the rule :
"Event pattern is not valid. Reason: Inside anything but list, start|null|boolean is not supported."
Am I missing something in the syntax or if this is a limitation then is there any alternative to this problem?
You can use prefix within an array in event pattern. Here is an example pattern:
{
"detail": {
"alarmName": [{
"prefix": "DemoApp1"
},
{
"prefix": "DemoApp2"
}
],
"state": {
"value": [
"ALARM"
]
},
"previousState": {
"value": [
"OK"
]
}
}
}
This event will match alarm that has name starting with either DemoApp1 or DemoApp2
TLDR: user #samtoddler is sort of correct.
Prefix matches only work on values as called out in https://docs.aws.amazon.com/eventbridge/latest/userguide/content-filtering-with-event-patterns.html#filtering-prefix-matching. They do not work with arrays. You can file a feature request with AWS support but if you'd like to unblock yourself; you it's probably best to either control the prefixes you have for userName (guessing this is something IAM related and in your control).
If that's not possible; consider filtering as much as you can via other properties before sending over to a compute (probably lambda) to performing additional filtering.
I want to use some dictionary based stemming via the hunspell token filter. I am using Amazon Elastic Search, but not getting how to configure these plugins to my domain. If any other dcitionary stemmer is available in AWS ES then it will be helpful. This service is turning out to be useless.
Looks like there is no way to do this. But to get the stemming working, i have used english stemmer, which works well for english words.
I have created a custom analyzer with following settings:
"analysis": {
"filter": {
"english_stemmer": {
"type": "stemmer",
"language": "english"
},
"english_possessive_stemmer": {
"type": "stemmer",
"language": "possessive_english"
}
},
"analyzer": {
"english": {
"tokenizer": "standard",
"char_filter": [
"html_strip"
],
"filter": [
"asciifolding",
"english_possessive_stemmer",
"lowercase",
"stop",
"english_stemmer"
]
}
}
}
[
{
"id": 1,
"name": "MetaOperationN1",
"type": "Operation"
},
{
"id": 2,
"name": "GreenOper2",
"type": "Operation"
},
{
"id": 3,
"name": "GreenOper4",
"type": "Operation"
},
{
"id": 4,
"name": "GreenOper5",
"type": "Operation"
},
{
"id": 5,
"name": "GreenOper6",
"type": "Operation"
},
{
"id": 6,
"name": "GreenOper7",
"type": "Operation"
},
{
"id": 7,
"name": "GreenOper8",
"type": "Operation"
},
{
"id": 8,
"name": "GreenOper9",
"type": "Operation"
},
{
"id": 9,
"name": "GreenOper10",
"type": "Operation"
},
{
"id": 10,
"name": "GreenOper11",
"type": "Operation"
}
]
Using Regular Expression Extractor with following configuration:
Reference Name: anything meaningful, i.e. ID
Regular Expression: "id": (\d+),
Template: $1$
Match No.: -1
Using JSON Path Extractor (available via JMeter Plugins)
Reference Name: whatever you want, i.e. ID
JSONPath Expression: $..id
In both cases you'll get IDs list as:
ID_1=1
ID_10=10
ID_2=2
ID_3=3
ID_4=4
etc.
For more information on installing JSON Path Extractor and regarding JSON Path language check out Using the XPath Extractor in JMeter (scroll down to "Parsing JSON")
Dont use regex for parsing json docs.. easily done by referring this
If you want to use regex.. go ahead:
"id": (\d+)
And extract out ids with $1