Sample Text:
\- !ruby/object:DynamicAttribute
attributes:
resource_id: "1"
resource_type: Applicant
string_value: "Michael"
int_value:
id: "35972390"
date_value:
name: first_name
attributes_cache: {}
\- !ruby/object:DynamicAttribute
attributes:
resource_id: "1"
resource_type: Applicant
string_value: "Johnson"
int_value:
id: "35533149"
date_value:
name: last_name
attributes_cache: {}
Target:
I'm trying to extract the value after "string_value" where the "name" equals some string. Let's say it equals last_name. The attributes are not in any particular order. I've explored using capture groups but I did not get very far.
Any help on this would be appreciated. Thanks!
You can try this regex:
Explanation
string_value:
matches the charactersstring_value:
(?=(?:(?!attributes_cache).)*name: last_name)
it looks ahead to see if it containsname: last_name
but will not go beyond attributes_cache , otherwise it may overlap with the next result set which may have name: last_name\s+
matches any whitespace character (equal to [\r\n\t\f\v ])\"
matches the character"
literally (case sensitive)(\w+)
: \w+ matches any word character (equal to [a-zA-Z0-9_]) => this is the text that you want capture.The capture group 1 contains the text that you are looking for.
Although you haven't described the programming language but the following sample is done on ruby (run it) :