Extract the fields in json log if the filed exists using regex - regex
I am trying to extract the fields in the below sample data
{"Value":{"Data":{"Items":[{"FieldType":"ABC","Value":"*****"},{"FieldType":"ACB","Value":"*****"},{"FieldType":"ABCD","Value":"*****"},,{"FieldType":"XYZ","Value":"*****"}],"EncryptedDocKey":"*****","Domain":"*****","Partner":"***","Carrier":"****"},"RequestTrackerId":"****","Message":"OK"},"Formatters":[],"ContentTypes":[],"DeclaredType":null,"StatusCode":null}
{"Value":{"Data":{"Items":[{"FieldType":"ABC","Value":"*****"},{"FieldType":"XYZ","Value":"*****"},{"FieldType":"ACD","Value":"*****"}],,"EncryptedDocKey":"*****","Domain":"*****","Partner":"***","Carrier":"****"},"RequestTrackerId":"****","Message":"OK"},"Formatters":[],"ContentTypes":[],"DeclaredType":null,"StatusCode":null}
{"Value":{"Data":{"Items":[{"FieldType":"XYZ","Value":"*****"},{"FieldType":"ACD","Value":"*****"}],,"EncryptedDocKey":"*****","Domain":"*****","Partner":"***","Carrier":"****"},"RequestTrackerId":"****","Message":"OK"},"Formatters":[],"ContentTypes":[],"DeclaredType":null,"StatusCode":null}
{"Value":{"Data":{"Items":[{"FieldType":"ABCD","Value":"*****"}],,"EncryptedDocKey":"*****","Domain":"*****","Partner":"***","Carrier":"****"},"RequestTrackerId":"****","Message":"OK"},"Formatters":[],"ContentTypes":[],"DeclaredType":null,"StatusCode":null}
I need to extract the text next to FieldType (ABC,XYZ,ABCD,ACB,ACB ...) into V1,V2,V3,V4,V5 etc...
I have a regex that can get if there are three fields but the regex is not mapping if there are more or less than 3 fields.
I tried this regex
.?"FieldType":"(?<V1>\w+)".+?"FieldType":"(?<V2>\w+).+?"FieldType":"(?<V3>\w+)
Also I want to extract all the fields in fieldtype and ,EncryptedDocKey,Domain,Partner,Carrier,RequestTrackerId,Message,Formatters,ContentTypes,DeclaredType,StatusCode
It'd be unnecessary to apply regular expressions here, yet if you have to, an expression similar to:
"(FieldType)":"([^"]+)"|"(message)":"([^"]+)"
might extract those desired key values.
DEMO
Related
How to compare two string using RegEx
I have a collection in the MongoDB which has list of URLs like below. In my business logic for some requirements, I want to check whether the called URL is matching with any of the records in the DB records. like req.originalUrl i get suppose /logistics/initiator/5ee7a0be36acdc46ae0576d6/users But in the above URL obviously, I'm getting the actual Id -- 5ee7a0be36acdc46ae0576d6 What i tried: I tried manually concatinating the req.baseUrl and req.route.path but that still gives me the below string /logistics/initiator/:initiator/users which is again incomparable.
Replace the ID with \{\w+\}, and use that as a regular expression to match against the url column in the table. So the regexp should be /logistics/initiator/\{\w+\}/users.
Mariadb: Regexp_substr not working with non-matching group regular expression
I am using a query to pull a user ID from a column that contains text. This is for a forum system I am using and want to get the User id portion out of a text field that contains the full message. The query I am using is SELECT REGEXP_SUBSTR(message, '(?:member: )(\d+)' ) AS user_id from posts where message like '%quote%'; Now ignoring the fact thats ugly SQL and not final I just need to get to the point where it reads the user ID. The following is an example of the text that you would see in the message column `QUOTE="Moony, post: 967760, member: 22665"]I'm underwhelmed...[/QUOTE] Hopefully we aren’t done yet and this is nothing but a depth signing!` Is there something different about the regular expression when used in mariadb REGEXP_SUBST? this should be PCRE and works within regex testers and should read correctly. It should be looking for the group "member: " and then take the numbers after that and have a single match on all those posts.
This is an ugly hack/workaround that works by using a lookahead for the following "] however will not work if there are multiple quotes in a post (?<=member: )\.+(?="])
How do I use regex to return text following specific prefixes?
I'm using an application called Firemon which uses regex to pull text out of various fields. I'm unsure what specific version of regex it uses, I can't find a reference to this in the documentation. My raw text will always be in the following format: CM: 12345 APP: App Name BZU: Dept Name REQ: First Last JST: Text text text text. CM will always be an integer, JST will be sentence that may span multiple lines, and the other fields will be strings that consist of 1-2 words - and there's always a return after each section. The application, Firemon, has me create a regex entry for each field. Something simple that looks for each prefix and then a return should work, because I return after each value. I've tried several variations, such as "BZU:\s*(.*)", but can't seem to find something that works. EDIT: To be clear I'm trying to get the value after each prefix. Firemon has a section for each field. "APP" for example is a field. I need a regex example to find "APP:" and return the text after it. So something as simple as regex that identifies "APP:", and grabs everything after the : and before the return would probably work.
You can use (?=\w+ )(.*) Positive lookahead will remove prefix and space character from match groups and you will in each match get text after space.
I am a little late to the game, but maybe this is still an issue. In the more recent versions of FireMon, sample regexes are provided. For instance: jst:\s*([^;]?)\s; will match on: jst:anything in here; and result in anything in here
Searching a number in a specific string with regexp in jmeter
I want to find a specific number from a HTML response. For example, I want to extract 3 from publicationID3publicationID. Does someone know a solution with regexp?
Add Regular Expression Extractor Post Processor as a child of the request, which returns to you this string. Configure it as follows: Reference Name: publicationID (you can use any variable name here) Regular Expression: publicationID(\d+)publicationID Template: $1$ other fields can be left blank. You can later refer publication ID as ${publicationID} or ${__V(publicationID)} You can see what matches does your Regular Expression return using View Results Tree Listener (select RegExp Tester from dropdown). Another option is Debug Sampler again with combination with View Results Tree.
you can use \d to match a number using regex.
How to use regex for querying in Solr 4
I've reached the point of desperation, so I'm asking for help. I'm trying to query results from a Solr 4 engine using regex. Let's asume the document I want to query is: <str name="text">description: best company; name: roca mola</str> And I want to query using this regex: description:(.*)?company(.*)?; I read in some forums that using regex in Solr 4 was as easy as adding slashes, like: localhost:8080/solr/q=text:/description\:(.*)?company(.*)?;/ but it isn't working. And this one doesn't work either: localhost:8080/solr/q=text:/description(.*)?company(.*)?;/ I don't want a simple query like: localhost:8080/solr/q=text:*company* Since that would mismatch documents like: <str name="text">description: my home; name: mother company"</str> If I'm not clear please let me know. Cheers from Chile :D NOTE: I was using text_general fields on my scheme. As #arun pointed out, string fields can handle the type of regex I'm using.
Instead of trying regex search on text field type, try it on a string field type, since your regex is spanning more than one word. (If your regex needs to match a single word, then you can use a text field.) Also do percent encoding of special characters just to make sure they are not the cause for the mismatches. q=strfield:/description%3A(.*?)company(.*?)%3B.*/ Update: Just tried it on a string field. The above regex works. It works even without the percent encoding too i.e. q=strfield:/description:.*?company.*?;.*/