[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2649
  • Last Modified:

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!
0
Dallas Smetter
Asked:
Dallas Smetter
  • 4
  • 3
  • 2
1 Solution
 
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now