.net - How can you match all but the last word of a line? -


i want 2 strings. last word on line (which works below) , last word, , want regex. suggested use ^(.*?)\b\w+$ pattern , use $1 match (but have no idea how accomplish in .net)

    dim s string = "   time men come aid of country    "     s = regex.replace(s, "^[ \s]+|[ \s]+$", "")  'trim whitespace     dim lastword string = regex.match(s, "\w*$", regexoptions.none).tostring     debug.print(lastword)      dim therest string = regex.match(s,......) 

your pattern should work, , you're looking first capture of match collection:

dim pattern string = "^(.*?)\b\w+$"  ' use trimend instead of regex replace (i.e. don't nuke ant piles) dim match match = regex.match(input.trimend(), pattern)  if match.success     ' 0th capture on 1st group     dim allbutthelast string = match.groups(1).captures(0)     ' group 0 entire input matched end if 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -