Highlighted
vidz Respected Contributor.
Respected Contributor.
520 views

Need help in writing regular expression.

Dear Experts,

could you please help me in writing regular expression for below URL:

 

Information on 2018 Senior Exec Annual Review for XYZ PQR (Document ID=4704)" class="pmFormInformation"
                //href="/acme?bplte_company=departme02T1&fbacme_o=my_forms&myf%5fos=inbox&myf%5fss=&myf%5fmode=&inbox%5ffbfl%5fftype=Review&inbox%5fos=list&reqOrig=pm&page%5fno=1&inbox%5ffbfl%5fflist%5fact=get%5finfo&inbox%5ffbfl%5fftype=Review&inbox%5ffbfl%5fflist%5ffmid=4149&_s.crb=XO%2fP6fi7uCfhrojB

 

I want to extract values marked in amber. and feed in web_reg_save_param_regexp.

Thanks,

Vidz

 


        
    

Labels (1)
Tags (1)
0 Likes
3 Replies
Outstanding Contributor.. JHF Remmelzwaal Outstanding Contributor..
Outstanding Contributor..

Re: Need help in writing regular expression.

Use two regular expressions (put it in your web_save_param_regexp function, consult help for other parameters):

"RegExp=Document ID=(\\d+)"

"RegExp=ffmid=(\\d+)"

Try it yourself at https://regex101.com/

0 Likes
vidz Respected Contributor.
Respected Contributor.

Re: Need help in writing regular expression.

Hi JHF,

Issue here is both the dynamic values are with respect to the employee name XYZ PQR so I need to convert whole string into regular expression.

In the response I may get response (ike this) for other employees as well so for capturing document ID and ffmid specific to each user , I need to write RegRx.

I have developed something but it is giving me error.

"RegExp=/{EmpName}\\ {EmpSurname}\\ \\(Document\\ ID=(.*?)\\)\"\\[A-Za-z0-9\\\"\&\;\%\\\=]+\\ffmid=(.*)&/",

 

Could you please suggest.

Thanks,

Vidz

0 Likes
Outstanding Contributor.. JHF Remmelzwaal Outstanding Contributor..
Outstanding Contributor..

Re: Need help in writing regular expression.

You change the rules during the game :-).

1 Do you need the id-information of one, multiple or (allmost) all employees?

2 Looking to your RegExp string I see a few things I do not understand:

2a No need to put regular expression between '/' (I did not do that as well).

2b If you expect numbers use '\d+' and not '.*?'

2c You are inserting '\ ' (escaped spaces) why? You can use \s for any whitespace if you like.

2d. Your large character set (all the tokens between '[' and ']' do not need escapes. Just use instead '.*?' it will then move on just till next 'ffmid'

Assume you need all values you might use as expression:

"RegExp=for (.*?) \\(Document ID=(\\d*).*?ffmid=(\\d+)&"

It captures any name expression and the two IDs (please test this on regex101.com and see how it matches with your data).

 

You can include the following three function calls (all same RegExp)

web_reg_save_param_regexp(
    "ParamName=ReviewName"
    , "RegExp=......"
    , "Group=1"
    , "Ordinal=All"
    , Last );

web_reg_save_param_regexp(
    "ParamName=ReviewDocId"
    , "RegExp=......"
    , "Group=2"
    , "Ordinal=All"
    , Last );

Note: the  third call is an exercise for you....

Each call will register one group of the regexp into an array of the parameter name. Use the functions lr_paramarr_len() and lr_paramarr_idx() to search for the right name and corresponding IDs.

Success.

P.S.

Examine this topic as well.

Read the LR help on the above functions over and over again till you understand the details.

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.