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?
 
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
 
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
 
SurranoSystem EngineerCommented:
Another solution:

(....)$

simple as it is.
1
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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
 
SurranoSystem EngineerCommented:
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
 
SurranoSystem EngineerCommented:
Not damned... You just embarrass me :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.