I Want to extract the data by using regex input #RG 13828 ABCDEF.HIJKL

Hi team,

I need to extract data after the digit, I have given the example input below.

Input: #RG 13828 ABCDEF.HIJKL

Hear I need to expecting only ABCDEF HIJKL

Note: In the input, we have “#RG” as a constant, and it will always be followed by a pattern of a space, digits, and then the value.

I tried using the pattern ((?<=RG#\s)\d+\s(.*)) and it worked, but I prefer not to use it because when printing the value, we would have to write it as “opregex(1).value”. I want to print the output as “opregex(0).value” instead. This way, the increment of 0 by adding 1 will keep changing.

Please can anyone help me to resolve the issue?

Thanks.

@copy_writes

Please try this

(?<=#RG \d+ ).*

cheers


Try this
cheers

Hi @copy_writes

Follow the below regex Expression to achieve the output:
You can use it in Matches activity or in assign activity in the following way"

Regex Expression: (?<=[0-9]\s)(.*)
System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“ (?<=[0-9]\s)(.*)”).toString

Note: Attached the workflow below for reference
Sequence1.xaml (8.0 KB)

Hope ite helps!
Regards,

Yes, it will work but I use a logic for that it won’t work. Because I am extract the value after #RG digit. so I increment the value.

input may be like this
RG# 13828 ABCDERG HIJK LMNOP
TUJAH KKK KADFF TAGE,
ASSETS $326,536.37 X .05000% / 12 X 100.00% X 1 = $13344


TOTAL $132884961

RG# 23456 ABCDERG HIJK LMNOP
TUJAH KKK KADFF TAGE,
ASSETS $326,536.37 X .05000% / 12 X 100.00% X 1 = $13344


TOTAL $132884961

this wont work if we use + inside look behind we get pattern error.

I’m following the below steps.

Regex: (?<=RG#\s).*
Substring: opRegex(index).value.Substring(opRegex(index).value.IndexOf(" ") + 1).trim

Result: Expected.

@copy_writes

C# supports plus inside the look behind also…it would work…it was already tested…please let me know if you face issues

image

Pattern error for php

Cheers

1 Like

how you use this in UiPath studio? and find match is not support for this


you can try once its working
System.Text.RegularExpressions.Regex.Match(inputstr,“(?<=[#RG]?[0-9]\s).“)
[ABCDEF.HIJKL]
or
System.Text.RegularExpressions.Regex.Match(inputstr,”(?<=#RG \d+\s).
”)
[ABCDEF.HIJKL]

@copy_writes

Use assign activity directly on left give a string variable(requiredstring) and on right use the expression

requiredstring = System.Text.RegularExpressions.Regex.Match("#RG 13828 ABCDEF.HIJKL","(?<=#RG \d+ ).*").Value

cheers

Hi @copy_writes

Follow this regex expression it will work for both kind of Inputs you have provided.

(?<=(RG#|#RG)\s[0-9]+\s)(.*)

Note: Refer the workflow for reference
Sequence1.xaml (9.3 KB)

Hope it helps!!
Regards,

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