c# - Regex for numbers after a certain string part -
i'm trying extract numbers inside url regex.
example input: http://localhost:23089/generic-url-segment-c?p=5 expected output : 5 example input: http://localhost:23089/generic-url-segment-c?p=12&sort=5 expected output: 12 first tried numbers mixture of string.replace,string.indexof , substring thought regex easier.
so far tried using ((p=)?=.) can't 5 only.
and shown in second example, value might 2 digit value or there might other parameters after it. maybe search between p= , & necessary don't know how regex behaves in absence of parameters.
try below pattern. plus matches 1 or more can 1 or more digits -
p=(\d+) the brackets group value of match within group use
match.groups[0].value wiki
Comments
Post a Comment