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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:07:15+00:00 2026-05-15T05:07:15+00:00

I am looking for a regular expression for matching that contains no white space

  • 0

I am looking for a regular expression for matching that contains no white space in between text but it may or may not have white space at start or end of text.

  • 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-15T05:07:15+00:00Added an answer on May 15, 2026 at 5:07 am

    You want something like this: (see it in action on rubular.com):

    ^\s*\S+\s*$
    

    Explanation:

    • ^ is the beginning of the string anchor
    • $ is the end of the string anchor
    • \s is the character class for whitespace
    • \S is the negation of \s (note the upper and lower case difference)
    • * is “zero-or-more” repetition
    • + is “one-or-more” repetition

    References

    • regular-expressions.info/Anchors, Character Classes and Repetition

    Can the “text” part be empty?

    The above pattern does NOT match, say, an empty string. The original specification isn’t very clear if this is the intended behavior, but if an empty “text” is allowed, then simply use \S* instead, i.e. match zero-or-more (instead of one-or-more) repetition of \S.

    Thus, this pattern (same as above except * is used instead of +)

    ^\s*\S*\s*$
    

    will match:

    • The empty string (i.e. the string whose length is 0)
    • Non-empty strings consisting of nothing but whitespace characters

    What counts as “text” characters?

    The above patterns use \S to define the “text” characters, i.e. anything but whitespace. This includes things like punctuations and symbols, i.e. the string " #@^$^* " matches both patterns. It’s not clear if this is the desired behavior, i.e. it’s possible that " ==== AWESOMENESS ==== " is a desired match

    The pattern still works even for this case, we simply need to be more specific with our character class definitions.

    For example, this pattern:

    /^[^a-z]*[a-z]*[^a-z]*$/i
    

    Will match (as seen on rubular.com):

     ==== AWESOMENESS ====
    

    But not:

     ==== NOT AWESOME ==== 
    

    Note that the ^ metacharacter, when used as the first character in a character class definition, no longer means the beginning of the string anchor, but rather a negation of the character class definition.

    Note also the use of the /i modifier in the pattern: this enables case insensitive matching. The actual syntax may vary between languages/flavors.

    References

    • regular-expressions.info/Modifiers
    • java.util.regex.Pattern.CASE_INSENSITIVE — embedded flag is (?i)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a regular expression that detects whether or not a string is
I'm looking for a regular expression that can find the alpha representation of a
I am looking for a regular expression for c# asp.net 3.5 that will fail
I have been looking for a regular expression with Google for an hour or
I am looking for a single regular expression that will replace all replace me
Looking for a regular expression that match the following relative URLs: All urls starts
I am looking for a regular expression that will accept date formats, both MM/DD/YYYY
I'm looking for a regular expression testing program that I had installed on my
I'm looking for a regular expression that will match all strings EXCEPT those that
I am looking for a regular expression using preg_match_all in PHP 5 that would

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.