Highlighted
Contributor.
Contributor.
119 views

Require assistance in regular expressions in LR

","(1) 1st PartyVehicle - Marie-Madeleine Walravens-Civil Liability","Exposure"

","(1) 1st PartyVehicle - Ralph Kordel-Accident Vandalism","Exposure"]

Above are the two possible responses we receive in rawdata when tried with two different policy numbers where the highlighted bold data is the dynamic value that change for each policy number.

 

How do I use regular expressions to capture
LB: ","(1) 1st PartyVehicle
RB: ","Exposure"]

Note:

I have used the below web_reg_save_param function:

web_reg_save_param_regexp(
        "ParamName=RelatedTo",
        "RegExp=1st PartyVehicle -(.*?)-(.*?)\",\"Exposure\"]",
        "Group=1",
        SEARCH_FILTERS,
        "Scope=BODY",
        LAST);

 

But this only works for 2nd  case and not for the 1st case. How do we write a function that matches for both the cases?

0 Likes
2 Replies
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: Require assistance in regular expressions in LR

Hi Haarthy123, 

I never use the function for more than one string, but have you tried with the "Ordinal" attribute set to "All"? With this setting, all the occurrences of the match are saved. 

web_reg_save_param_regexp(
        "ParamName=RelatedTo",
        "RegExp=1st PartyVehicle -(.*?)-(.*?)\",\"Exposure\"]",
        "Group=1", "Ordinal=All",

        SEARCH_FILTERS,
        "Scope=BODY",
        LAST);

Let me know. Otherwise, we can try with two web_reg_save_param() functions without regular expressions.

Lorenzo

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Require assistance in regular expressions in LR

As mentioned before in reg-exp topics: check your reg-exps at: regex101.

The issue with your first name, is that it contains (surrounding quotes are not part of any expression) a '-', and your match against '.*?'. The latter implies short possible match. So group 1 will stop at first '-'. Also your first example line does not ends with a ']' as requested in your regexp.

When I read your two examples: the first part before '-' (in general) contains a name with possible '-' and second part after '-' does not contain a '-'. When I introduce the rule that both expressions will never contain double quote we can replace '.*?' with '[^"]*' for the first group and '.*?' with '[^"-]*' for the second group. You expression becomes then (Now in C-code notation):

"RegExp=1st PartyVehicle - ([^\"]*)-([^\"-]*)\",\"Exposure\"",

Note: I also removed the ']' at the end of your regexp, so it matches with both lines. (I think @lb1 thinks that you want to match a list of those name - policy sections, because your example match with json-list.

Note: According your problem description you like to have only one group for both name and policy.

Signature:
Reward community members who take time to respond and help.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.