c# - Regex to match the second word of a sentence and trim leading white space -
I am trying to write a reggae that matches another word in a sentence.
I have yet to be
\ s + [^ \ s] +
which mail
Blockquote>Quick
/ P>Unfortunately, I can not come up with a solution that removed the major white space.
See for example
So, is there an easy way to match "Quick" without white space? The weapon of choice is C #, if it makes a difference
and it has to be regex, I know that String.Split
will be very good in this specific situation.
On the one hand, is it possible to match the word N-th in Regex? I know that what an unknown number of regex groups can not group, is this right?
Edit : My example had a typo. The underscores I had to highlight was to highlight the white space.
The regular expression you are using is correct. To get around your problem, you can use the Capture group
, something like this:
string str = "Quick brown pendant on a celestial dog Jumps "; Reggae's R = New Reggae (@ "\ s + ([^ \ s] +)"); Match M = R. Match (straw); System.Console.WriteLine (m.Groups [1]);
This will generate quick
without the previous location.
Alternatively, you can use the trim ()
method on your results too.
In addition, according to your party's note, you can match the word given with a combination of C # and Regex to the nth
word, something you need to do Should:
string str = "quick brown fox jumps on celestial dog"; Reggae's R = New Reggae (@ "(| | | | \ s) + ([^ \ s] +)"); Matching MC = R. Matts (ARR); For (Int i = 0; I
yield:
Quick brown jumps on lazy dogs jumps
I had to amend it Keep in mind the first word as well as Regex. This allows the resuscence to choose words that either start on a white space or start the string.
According to your comment, please take a look at the link.
Comments
Post a Comment