How to get last 3 characters from a string using regex [duplicate] - regex

This question already has answers here:
Regular expression to get last 3 characters of a string
(2 answers)
Closed 5 years ago.
how to get last 3 or 5 digits from this given one using regex
4c113866bc43e2be48bbf85be829d7bc

Use $ anchor to mark the end of the string:
.{3,5}$
3 above is the min number of characters to match; 5 is max.

Related

Regex ignore match more than one dots [duplicate]

This question already has answers here:
Comma Separated Numbers Regex
(6 answers)
Regular Expression to match dot separated list with no dot on the end and allow asterisk at the end
(3 answers)
c++ regexp allowing digits separated by dot
(2 answers)
Closed 4 months ago.
/^[0-9][0-9-.]*[0-9]+$/u
I am trying to match with these like codes:
1.11122.5454.545
55
555.55
65656.75454
Not 111..444 and not 44545...444
How can I stop more than 1 dots between numbers

How to match float numbers without empty matches [duplicate]

This question already has answers here:
RegEx validation of decimal numbers with comma or dot
(6 answers)
How to extract decimal number from string in C#
(7 answers)
Closed 2 years ago.
I've custom regex where I match float numbers.
Regex:
/[0-9]*\,?[0-9]*\.?[0-9]*/m
When I tried with string 1,5$+absd1.5a get 10 matches on result where 1 match == 1,5 and 8 match = 1.5. Other matches is empty. How I can match without empty results?
Demo
https://regex101.com/r/jnhsly/1

Regular expression match with public key [duplicate]

This question already has answers here:
Match exact string
(3 answers)
Closed 4 years ago.
Hi this is my example 0xc1e5017fbc68aa3e56aa580708de9aa123d62d18
This is my reg ex ^0x[a-fA-F0-9]{1,40}. What I'm doing is 0x which is compulsory after that we can enter upto 40 alpha numeric digits. But not special characters. What should I do here so it will match correctly?
Your issue is that you need to assert where the string ends, or else you will match up until a special character is found, and get undesired matches.
So with your current regex and test string 0xc1!, 0xc1 would be matched, even though it is an invalid match.
How about using: ^0x[a-fA-F0-9]{1,40}$

Matches a string containing two variables using a regular expression [duplicate]

This question already has answers here:
PHP: RegEx for string with 3-9 letters and 5-50 numbers
(2 answers)
Closed 5 years ago.
I want to match a string that has the following requirements:
The string contains 5 to 10 digits. [0-9]
Contains 2 to 3 letters. [a-z]
for example
123a2bc12
s123d456
This is my regular expression. /^\d*[a-z]\d*[a-z]\d*[a-z]?\d*$/. But this can only limit the number of letters.
It isn't pretty but this should be what you're looking for:
^(?=(?:[^a-zA-Z]*[a-zA-Z]){2,3}[0-9]*$)(?=(?:[^0-9]*[0-9]){5,10}[A-Za-z]*$).*$
I think you want to this
s=re.search(r'(\w+)','123a2bc12').group(1)
print s #The output is '123a2bc12'

Regular expression to restrict number of digits in a string [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to have a regular expression to restrict the number of digits in a string which may contain alphabets or any other characters along with digits. Is this possible with regular expressions ?
The idea is to anchor beginning and end of string and allow exactly n repetitions of a digit with something else. For example, exactly 6 digits in a string:
^\D*(\d\D*){6}$