Code working in Regex not working in uipath

“(?<=Grand Total)(.?\n?)(?=Original|1.\s{0,1}Air)”

This regex code is working fine in regex101 but not working in uipath studio.

@jishnupnair1996 Is it possible to attach your workflow?

Hi @indra happy to see that u have replied.
But unfortunately i am not to attach the work fliow

i will attach the text file in which i am working

“r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tCurrency : INR\r\nDescription SAC Code Taxable\r\nValue\r\nNonTaxable\r\n/Exempted\r\nValue\r\nTotal\r\nIGST\r\nTax % Amount\r\nCGST\r\nTax % Amount\r\nSGST/UGST\r\nTax % Amount\r\nTotal(Incl\r\nTaxes)\r\nAir Travel and related charges 996425 11,979.00 0.00 11,979.00 5.00 599.00 0.00 0.00 0.00 0.00 12,578.00\r\nAirport Charges 0.00 165.00 165.00 0.00 0.00 0.00 0.00 0.00 0.00 165.00\r\nGrand Total 11,979.0\r\n0\r\n165.00 12,144.00 599.00 0.00 0.00 12,743.00\r\nOriginal Invoice Number: DL1181911BP77963\t\tDate: 10-Nov-2018\r\n1. Air Travel and related Charges :- Includes all Charges related to air transportation of passengers\r\n2. Airport Charges :- Includes ADF,UDF,PSF and other airport charges collected on behalf of Airport Operator,as applicable\r\n3. Misc. Services :- Includes Charges of Lounge,Medical Assistance and Travel Certificate\r\n4. Meal :- Includes all prepaid meals purchased before travel\r\n5. Good Karma :- Includes contributions made towards IndiGo’s Good Karma initiative and Clear the Air initiative\r\n \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t made at the time of reservation\r\n6. Amounts have been rounded off.\r\n”

here in this the code work in regex101 but not working in uipath studio

@jishnupnair1996 Whats the result you need from above text file?

[quote=“jishnupnair1996, post:3, topic:95057”]
]

11,979.0\r\n0\r\n165.00 12,144.00 599.00 0.00 0.00 12,743.00

(?<=Grand Total)(.*?\n*?)(?=Original|1\.\s{0,1}Air)

Sorry this is the code
@indra

@jishnupnair1996 after “original” there is no “Air” word in your text.

some pdf files it may come
thats why i put it as an option
@Manjuts90

@jishnupnair1996 Try below Regex.

“(?<=Grand Total)(.?\n?)(?=Original(|1.)?\s?(Air)?)”

@Manjuts90

Sorry it wont work.

output is like this

CastIterator
{

}

Use .Groups to get the output.

eg:

RPO(0).Groups(1).Value.tostring (where RPO is your vairable and 0 is it’s index and 1 is the group number)

Hi @jishnupnair1996,

Please assign, string str= System.Text.RegularExpressions.Regex.Match(your_string,"((?<=Grand Total)[\s\S]+?(?=Original))").ToString.Replace("\r\n"," ")

Regards,
Nimin

Hi @jishnupnair1996,

If you want to extract the text between “Grand Total” and “Air” , if the string “Original” is not present, please assign str = System.Text.RegularExpressions.Regex.Match(str,"(?<=Grand Total)[\s\S]+?((?=Original)|(?=(1.\sAir)))").ToString.Replace("\r\n"," ")

Warm regards,
Nimin

@jishnupnair1996 I checked same regex with your input and it is giving correct output.

Thanks @nimin
it worked well…

can you please explain the regex code also. it may help me to study more about regex

sorry it is not working in my case

Hi @jishnupnair1996,

(?<=Grand Total)[\s\S]+?((?=Original)|(?=(1.\sAir)))

(?<=xxx) and (?=xxx) are look behind and look ahead tokens, which searches for patterns after (?<=xxx) and before (?=xxx) without including the string ‘xxx’ in the result.
In between those strings, we need to capture everything. If we use .* it will skip line break. so [\s\S]+ helps to capture one or more occurrence of any white space characters(\s including [\r\n\t\f\v ]) and any non whitespace characters(\S) in the result. "|" operator acts as a logical OR condition.
I hope you got it now.:slightly_smiling_face:

Warm regards,
Nimin

1 Like

Thanks Bro…

1 Like

Thank you for the advantages that you bring us. We have a lot of new knowledge. We can take it right. It’s good.:ta pollballtoyou.com

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.