regex for allowing SINGLE white space in between words
I m using the following regex for the same:
^S.*S$
but this regex is not working in case of multiple spaces in between words.
and one more thing, it doesnt allow you to enter a single character
I want to validate no leading and trailing space and single white space in between words, words can include anything alphanumeric as well as special character.
if i m trying to enter 'a' in the text box, its not accepting
regex
|
show 3 more comments
I m using the following regex for the same:
^S.*S$
but this regex is not working in case of multiple spaces in between words.
and one more thing, it doesnt allow you to enter a single character
I want to validate no leading and trailing space and single white space in between words, words can include anything alphanumeric as well as special character.
if i m trying to enter 'a' in the text box, its not accepting
regex
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
1
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
1
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04
|
show 3 more comments
I m using the following regex for the same:
^S.*S$
but this regex is not working in case of multiple spaces in between words.
and one more thing, it doesnt allow you to enter a single character
I want to validate no leading and trailing space and single white space in between words, words can include anything alphanumeric as well as special character.
if i m trying to enter 'a' in the text box, its not accepting
regex
I m using the following regex for the same:
^S.*S$
but this regex is not working in case of multiple spaces in between words.
and one more thing, it doesnt allow you to enter a single character
I want to validate no leading and trailing space and single white space in between words, words can include anything alphanumeric as well as special character.
if i m trying to enter 'a' in the text box, its not accepting
regex
regex
edited Dec 5 '14 at 12:13
Shashank Shekhar
asked Dec 5 '14 at 11:57
Shashank ShekharShashank Shekhar
1315
1315
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
1
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
1
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04
|
show 3 more comments
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
1
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
1
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
1
1
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
1
1
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04
|
show 3 more comments
3 Answers
3
active
oldest
votes
Seems like you want something like this,
^S+(?: S+)*$
S
matches any non-space character.
DEMO
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
add a comment |
[A-Za-z]+(s[A-Za-z]+)? you can use this to put single space between words
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
add a comment |
Just assert that two spaces don't appear;
^(?!.*ss)S(.*S)?$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27315412%2fregex-for-allowing-single-white-space-in-between-words%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Seems like you want something like this,
^S+(?: S+)*$
S
matches any non-space character.
DEMO
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
add a comment |
Seems like you want something like this,
^S+(?: S+)*$
S
matches any non-space character.
DEMO
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
add a comment |
Seems like you want something like this,
^S+(?: S+)*$
S
matches any non-space character.
DEMO
Seems like you want something like this,
^S+(?: S+)*$
S
matches any non-space character.
DEMO
answered Dec 5 '14 at 12:20
Avinash RajAvinash Raj
142k14115162
142k14115162
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
add a comment |
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
1
1
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
thanks buddy..this worked :)
– Shashank Shekhar
Dec 5 '14 at 12:25
add a comment |
[A-Za-z]+(s[A-Za-z]+)? you can use this to put single space between words
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
add a comment |
[A-Za-z]+(s[A-Za-z]+)? you can use this to put single space between words
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
add a comment |
[A-Za-z]+(s[A-Za-z]+)? you can use this to put single space between words
[A-Za-z]+(s[A-Za-z]+)? you can use this to put single space between words
answered Dec 5 '14 at 12:01
Sandy RawatSandy Rawat
399410
399410
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
add a comment |
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
i need to use alphanumeric as well as special characters and its not working if i want to enter a single character
– Shashank Shekhar
Dec 5 '14 at 12:05
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
@ShashankShekhar why you failed to add explanation in your question?
– Avinash Raj
Dec 5 '14 at 12:09
add a comment |
Just assert that two spaces don't appear;
^(?!.*ss)S(.*S)?$
add a comment |
Just assert that two spaces don't appear;
^(?!.*ss)S(.*S)?$
add a comment |
Just assert that two spaces don't appear;
^(?!.*ss)S(.*S)?$
Just assert that two spaces don't appear;
^(?!.*ss)S(.*S)?$
answered Dec 5 '14 at 12:26
Bohemian♦Bohemian
295k64415553
295k64415553
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27315412%2fregex-for-allowing-single-white-space-in-between-words%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"Working" and "not working" suggest you know what you want, but I can't tell from reading this what that is. Provide some examples of input and desired output and you'll get better answers.
– Edward
Dec 5 '14 at 11:59
What are you trying to achieve? Post some examples for valid and invalid matches.
– Avinash Raj
Dec 5 '14 at 11:59
this regex should give true for following: shashank shekhar
– Shashank Shekhar
Dec 5 '14 at 12:00
1
It will be better if your provide examples here. For input A expected output will be B.
– fhnaseer
Dec 5 '14 at 12:01
1
Add example in your question, not in comments,
– fhnaseer
Dec 5 '14 at 12:04