Regular expression not working but it works at Regex101

Hi people, I’m trying to extract a string from another string stored in a variable using regex but it shows no value. The regular expression seems to be correct.
Could you tell me what I’m doing wrong?

This is the text file content:

GA_AABOGSM8sid_limiteConsumo01
GA_AABOGSM8sid_umbralLimiteC01
GA_AABOGSM8sid_eventosLimite01
GA_AABOGSM8sflg_eventoLimite01
GA_AABOGSM8sflg_eventoUmbral01
GA_AABOGSM8sflg_eventoLimCon01
GA_AABOGSM8sflg_eventoUmbCon01
GA_AABOGSM8sflg_tasarAdicion01

RTN pkt(1) is :
rpr_srv_version 1
rpr_srv_flags 0
GA_AABOGSM8__rpr_ret 0
rpr_srv_name GA_AABOGSM8
GA_AABOGSM8_sSecActuacion 52798386548

[PREPO E6 arppga@mvlzffesg1]: Cert > exit

Last login: Thu Jun 8 11:28:54 2023 from 10.9.37.167

I describe the steps:

1- I read from a txt file using “Read text file” activity.

2- With an “assign” activity I extract some part of the string using regex and I store it in “portapapeles2” variable.
System.Text.RegularExpressions.Regex.Match(portapapeles,“((?<=GA_AABOGSM8_sSecActuacion)\s.*)”).Value
Result: " 52798386548"

3- I check with a “message box” activity if it captures the string I want. It does.

4- With an “Assign” activity I try to extract a string with a regex and store it in “portapapeles 3”. But this seems not to work.
System.Text.RegularExpressions.Regex.Match(portapapeles2,“\S\d*$”).Value
Result: “”

5- Message box “portapapeles3” shows no value.

What I want to achieve in the second assign is to select only the numbers and remove the whitespaces. The regex works in .NET Regex Tester - Regex Storm

Thanks in advance!
Juan

Hi @Juan_Paz, welcome to the Community.

In the step 4 of the above details:

Here, can you please try using portapapeles2.ToString in the expression?

Hope this helps,
Best Regards.

Hi. Thanks for the quick reply @arjunshenoy . Not working, it doesn’t show any value in the message box.
image

@Juan_Paz

I just observed that the RegEx pattern that you are using to retain the numbers & remove that whitespaces is not actually working when the whitespace is present in the end of the data.

If your sole purpose is to remove the whitespace, then I’d suggest you to go with the Trim function, like
portapapeles2.ToString.Trim

Or, if you are determined to achieve this via RegEx, please give the following pattern a try:

\s*(\d+)\s*

Hope this helps,
Best Regards.

1 Like

I checked your regex and it didn’t work but I tweaked it a bit and it’s working. The following did the work:
\S*\d\S*
Thanks a lot my friend @arjunshenoy .

1 Like

@Juan_Paz

Glad you made it across buddy. Seems like the pattern that you tweaked looks cool. Happy Automation!

Best Regards.

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