Hi,
I have a string. The last characters of the string are numbers. I want to substring or extract them. These are some examples of input strings: 'xdfg8941332', 'dder899945566445', 'cfgnnff89'. I have used 'find' with the following regex: \d+
, but it has not been successful.
Substring or extrac last characters
Hi
the regular expression r'\d+$'
is used to match one or more digits (\d+
) at the end of the string ($
)
![Collaborator Badge](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/eeb1807e-43ef-49be-9d57-ee7e35651ddc_thumb.png)
Thank you, I tried it and got this:
(str_Factura: XDGC992679)
Why does it show 0?
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/704d4c79-2941-4940-a491-28b837c3ff23.png)
Thank you, I tried it and got this:
(str_Factura: XDGC992679)
Why does it show 0?
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/704d4c79-2941-4940-a491-28b837c3ff23.png)
It is because the specified substring is not found. In your case you should use extract / substring. I believe you are using Find.
Hi
I got the result with below logic :
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/e2814985-d230-4cb7-8699-793b573a826e.png)
The key thing is I passed the RegEx in a variable and then send it to replace as it contains $ and AA checks for variable declaration.
The code works in fashion :
- List contains all the string where last numbers are to be extracted.
- Initially I replaced the last digits from the variable using RegEx : \d+$
- After that from the original string I removed the replaced text and got the desired Output.
Let me know if any query comes.
Hi
I got the result with below logic :
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/e2814985-d230-4cb7-8699-793b573a826e.png)
The key thing is I passed the RegEx in a variable and then send it to replace as it contains $ and AA checks for variable declaration.
The code works in fashion :
- List contains all the string where last numbers are to be extracted.
- Initially I replaced the last digits from the variable using RegEx : \d+$
- After that from the original string I removed the replaced text and got the desired Output.
Let me know if any query comes.
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/c301ef7b-b8c3-4622-b429-1030eab29b25.png)
Sample String has the input string and Regex has : \d+$ and is stored in Test1
![](https://uploads-us-west-2.insided.com/automationanywhere-en/attachment/745d5704-0e65-4da2-b555-d4f74b5acbe2.png)
Sample String has the input string, Test1 has the string other than last digits and the result is stored in OutPut
Example : Using String Replace
First Screenshot :
Input :
- SampleString : 12xd23fg8941332
- Regex = \d+$
Output :
- Test1 = 12xd23fg
Second Screenshot
- SampleString : 12xd23fg8941332
- Test1 = 12xd23fg
Output :
- OutPut = 8941332
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.