Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:15:40+00:00 2026-06-10T08:15:40+00:00

I am trying to extract the first character after the last underscore in a

  • 0

I am trying to extract the first character after the last underscore in a string with an unknown number of ‘_’ in the string but in my case there will always be one, because I added it in another step of the process.

What I tried is this. I also tried the regex by itself to extract from the name, but my result was empty.

var s = "XXXX-XXXX_XX_DigitalF.pdf"

var string = match(/[^_]*$/)[1]

string.charAt(0) 

So the final desired result is ‘D’. If the RegEx can only get me what is behind the last ‘_’ that is fine because I know I can use the charAt like currently shown. However, if the regex can do the whole thing, even better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:15:41+00:00Added an answer on June 10, 2026 at 8:15 am

    If you know there will always be at least one underscore you can do this:

    var s = "XXXX-XXXX_XX_DigitalF.pdf"
    
    var firstCharAfterUnderscore = s.charAt(s.lastIndexOf("_") + 1);
    
    // OR, with regex
    
    var firstCharAfterUnderscore = s.match(/_([^_])[^_]*$/)[1]
    

    With the regex, you can extract just the one letter by using parentheses to capture that part of the match. But I think the .lastIndexOf() version is easier to read.

    Either way if there’s a possibility of no underscores in the input you’d need to add some additional logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract first paragraph. But I have found any luck. Can any
I'm trying to extract the first user-right from semicolon separated string which matches a
I'm trying to extract the number from a text string and join it to
I am trying to extract the first complete number on each line from a
I am trying to extract a string that is located between the first and
I'm working in C#. I'm trying to extract the first instance of img tag
I am trying to extract the first letter of every word for a sentence
I'm trying to extract the first src attribute of an image in a block
I am trying to extract the first words in a file by Python. My
I am trying to extract character value from UTF-8 format. Suppose I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.