A
A
Alexto2018-07-21 12:23:08
Regular Expressions
Alexto, 2018-07-21 12:23:08

How to remove all characters except the last ones?

Hello, there is a lot of manual on regular expressions, but I didn't find the answer. SOURCE 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" Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2018-07-21
@Alexto

remove all characters except the last five to make "930-1"

Working example: regexr.com/3spqe .
We find 5 characters before the end of the line, you can add the necessary characters.
Working example: regexr.com/3spqb . Hover over the found fragment to see the contents of the first group.
We find a dash before the end of the line and take 5 characters before. They are in group #1 or named "last".
Working example: regexr.com/3spsa Lookahead
is used here.

D
Dimonchik, 2018-07-21
@dimonchik2013

you have a second condition with an example not from him
to expand your consciousness, use the advice: "not in one action", and not even all actions should be regexps
write what you do and what does not work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question