How to remove all characters, except the last one?

Hello, manual for full regexps, but have not found the answer

THE ORIGINAL STRING
blokupravlenijaimmobilajzeromalfaromeo14614i199838930-1

TASK
1. remove all characters except the last five, to get "930-1"
2. remove all characters except the last five after the last hyphen "38930"

Thanks in advance!
June 3rd 19 at 19:02
2 answers
June 3rd 19 at 19:04
Solution
remove all characters except the last five, to get "930-1"

Solution: [a-zA-Z0-9-]{5}$
Working example: regexr.com/3spqe.
Find before the end of the string is 5 characters, you can add the desired symbols.

remove all characters except the last five after the last hyphen "38930"

Solution #1: (?<last>[a-zA-Z0-9-]{5})-(.*?)$</last>
Working example: regexr.com/3spqb. Move the fragment to see the contents of the first group.
Find dash before the end of the row and pick 5 characters to. They are in group #1 or name "last".
5b53185433df0151116339.pngSolution #2: [^]{5}(?=-(.*?)$)
Working example: regexr.com/3spsa
Then used advanced test.
thanks, with your help, the first task so I decided [^]{5}$

the second solution is not realized, the result is obtained by a hyphen and the last digit 38930-1, and you need to only 38930 - nikita.Stracke commented on June 3rd 19 at 19:07
the result lies in the first group (first brackets and has a name last). Where the regular competition use, what language or program? I will write you an example. - deontae commented on June 3rd 19 at 19:10
use in the parser and there's no way to specify groups, so the result should be from the first group

5b531a930c420896313717.jpeg - nikita.Stracke commented on June 3rd 19 at 19:13
then , not even from the first, and null (includes all found a regular expression).
You actually read the documentation, usually allows to do the substitution, inserting a new value, something like \1 \2 or $1 $2 where the numbers correspond to groups.
And use forward validation: [^]{5}(?=-(.*?)$)
Working example: regexr.com/3spsa - deontae commented on June 3rd 19 at 19:16
June 3rd 19 at 19:06
you chotko the second condition with an example not from him

for the expansion of consciousness use the advice: "not one step", and not even all actions should be reexami

write what you do and what does not work

Find more questions by tags Regular expressions