SorenB
1
Hello
I am looking for a regex expression that will extract the desired value for a specific key, under a specific identifier.
The keys could move.
Example:
- Identifier: PersonDetails
- ValueForKey: lastname
Should give me the result “Doe”.
"elements":[
{
"identifier": "JobDetails",
"id": "asda892-241sad2-214sfs",
"values": {
"work address": "Random Road 2",
"city": "Random City",
"firstname": "Bob",
"lastname": "Johnsen"
}
}
{
"identifier": "PersonDetails",
"id": "sd89asd-gasg89-gasdf23",
"values": {
"firstname": "John",
"lastname": "Doe",
"age": 39
}
}
]
Regards
Soren
lrtetala
(Lakshman Reddy)
2
Hi @SorenB
(?<="identifier":\s+")\w+
(?<="lastname":\s+")\w+
Regards,
lrtetala
(Lakshman Reddy)
3
@SorenB
System.Text.RegularExpressions.Regex.Matches(Input,"((?<=""identifier"":\s+"")\w+)").Last.ToString
System.Text.RegularExpressions.Regex.Matches(Input,"((?<=""lastname"":\s+"")\w+)").Last.ToString
SorenB
4
What if the same key could be for more that one identifier.
I have updated the example.
I want the regex to find my desired “identifier” and then zoom to the “values” to search for the desired key inside those.
ppr
(Peter Preuss)
5
String looks like JSON, so we can process with JSON approaches
1 Like
ppr
(Peter Preuss)
7
we suggested above to base line on JSON. However a regex pattern could like this
and can also be finetuned
Hi @SorenB
Please find the below solution
- Use assign activity to find the identifier = PersonalDetails for rest of other details
strLastName = System.Text.RegularExpressions.Regex.Match(strInput, """identifier"":\s*""PersonDetails""[^{]*\{[^}]*""lastname"":\s*""([^""]+)").Value.ToString.Trim
- User assign acitivity to get the last name using the regex
strLastName = System.Text.RegularExpressions.Regex.Match(strLastName, "(?<=""lastname"":\s)(.*)").Value.ToString.Replace("""", "")
Output:
Thanks,
Purushotham
1 Like
Hi @batthula.p949 @SorenB
The strInput variable are the input variables that has my JSON ?
SorenB
10
Hello @ppr
Great thanks that seems like a usable approach
Best regards
Soren
system
(system)
Closed
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.