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.
Hi
the regular expression r'\d+$'
is used to match one or more digits (\d+
) at the end of the string ($
)
Thank you, I tried it and got this:
(str_Factura: XDGC992679)
Why does it show 0?
Thank you, I tried it and got this:
(str_Factura: XDGC992679)
Why does it show 0?
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 :
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 :
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.
Sample String has the input string and Regex has : \d+$ and is stored in Test1
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.