What would the syntax to get all the words in a string after the first space. For example, bobs nice house. So the result should be " nice house" without the quote.
([^\s]+)
gives me all 3 words seperated by ;
,[\s\S]*$ >
not compiling.
I was really looking shortest possible code. following did the job. thanks guys
\s(.*)
I think it should be done this way:
[^ ]* (.*)
It allows 0 or more elements that are not a space, than a single space and selects whatever comes after that space.
C# usage
var input = "bobs nice house";
var afterSpace = Regex.Match(input, "[^ ]* (.*)").Groups[1].Value;
afterSpace
is "nice house"
.
To get that first space as well in result string change expression to [^ ]*( .*)
No regex solution
var afterSpace = input.Substring(input.IndexOf(' '));
Actually, you don't need to use regex for that process. You just need to use String.Split()
method like this;
string s = "bobs nice house";
string[] s1 = s.Split(' ');
for(int i = 1; i < s1.Length; i++)
Console.WriteLine(s1[i]);
Output will be;
nice
house
Here is a DEMO
.
use /(?<=\s).*/g
to find string after first space.run snippet check
str="first second third forth fifth";
str=str.match(/(?<=\s).*/g)
console.log(str);