Regex: show the last n characters of a string

I have 36 characters strings, and I need to find out how to use a regex to just show the last 4 characters, whatever they may be.

Thank you in advance!
Dallas SmetterSolution EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
Assuming each 36 char string is on it's own line, you can use this:
^[^\n]+?([^\n]{4})$

and you'll have the last 4 characters in group 1.

In English: match the beginning of the line (^) and then as many non end-line characters as you can before the last 4 non end-line characters.

PS: why don't you use right(string, 4) in your favorite language?

HTH,
Dan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dallas SmetterSolution EngineerAuthor Commented:
Dan, yes I would just write the normal code but... in this particular instance, it's a front end management GUI that only accepts a regex as a parameter. I don't have access to the backend on this baby. Thanks!
0
Surranoapplication managerCommented:
Another solution:

(....)$

simple as it is.
1
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dallas SmetterSolution EngineerAuthor Commented:
Wish I could give some points to Surrano.
0
Dan CraciunIT ConsultantCommented:
You can.
Click on "Request attention" and ask a mod to reopen the question.
Then you can redistribute the points as you see fit.

HTH,
Dan
0
Dallas SmetterSolution EngineerAuthor Commented:
Step one has been performed.
0
Surranoapplication managerCommented:
C'mon I already saw that the question was closed before I answered. No need to redistribute points. Really.
0
Dallas SmetterSolution EngineerAuthor Commented:
Suit yourself, I was just trying to do what I thought was right. Damned if you do, damned if you don't...
0
Surranoapplication managerCommented:
Not damned... You just embarrass me :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.