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 6731069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:29:03+00:00 2026-05-26T10:29:03+00:00

The input string for regex is a casual number of chars from another string.

  • 0

The input string for regex is a casual number of chars from another string. So it can be an incomplete part of a word at the end of the input string. Regex must cut the incomplete part of the word and the space at the end of the string. Because there must be the whole word at the end of this string. So I wrote this to cut the incomplete part of the last word (C#):

Regex.Replace(s, @"([^\s]*){1}$", String.Empty)

As you see I use the space as the mark for the regex to stop cutting. But how to cut this space also? It must be in the same regex because I don’t want to use another regex or “Trim” functions for this simple operation. I know that it is easier to use TrimEnd but it is not graceful. So it’s just academic question. 🙂

  • 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-05-26T10:29:04+00:00Added an answer on May 26, 2026 at 10:29 am

    You can just include an optional space like so:

    \s?([^\s]*){1}$

    Which can be simplified:

    \s?\S*$

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

Sidebar

Related Questions

If I have input string in C#, how can I do series of Regex
I have a number of regex patterns. When a string is input I have
Assuming the input string +123-321+123 345 , using PHP's regex functions I would like
I need to retrieve a regex pattern matched strings from the given input. Lets
I have to parse an input string in python and extract certain parts from
How would I write a regex to take any input string and output only
I try build a php regex that validate this type of input string: {name:'something
I have this input string(oid) : 1.2.3.4.5.66.77.88.99.10.52 I want group each number into 3
I can't understand how to solve the following problem: I have input string aaaabaa
I need a regex that will verify whether the input string is in format

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.