Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Requires regex to compare last digit in string

Requires regex to compare last digit in string.

// For example: 
const reg = RegExp("anythink...5") // expression to check that the last number is 5
reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc") => true
reg.test("2fae71c8-fc5") => true
reg.test("2364872368745") => true
reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8") => false

Please help me find a solution.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use

/5(?=\D*$)/
/5(?!\D*\d)/

See the JavaScript demo:

const reg = /5(?=\D*$)/
console.log(reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc")) // => true
console.log(reg.test("2fae71c8-fc5")) //=> true
console.log(reg.test("2364872368745")) //=> true
console.log(reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8"))// => false

The 5(?=\D*$) regex matches

  • 5 - a 5 digit char
  • (?=\D*$) - a positive lookahead that requires zero or more non-digit chars till end of string
  • (?!\D*\d) - a negative lookahead that fails the match if there is a digit after 5 and any zero or more non-digit chars.
about 4 years ago · Juan Pablo Isaza Report

0

Use regexr.com to construct and check your Regular Expressions. You can even add multiple tests to see if it works for you in a glance.

about 4 years ago · Juan Pablo Isaza Report

0

You can match 5 optionally followed by any char except a digit or a newline using:

5[^\d\n]*$

You might also use \D* to match any char except a digit, but note that it could also match a newline.

See a regex demo.

const reg = /5[^\d\n]*$/; // expression to check that the last number is 5
console.log(reg.test("2fae71c8-a657-41b7-8d8c-3d4da10285fc")); // => true
console.log(reg.test("2fae71c8-fc5")); // => true
console.log(reg.test("2364872368745")); // => true
console.log(reg.test("87415B11-7143-4E5B-9B25-6117571DFEC8")); // => false

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!