Sunday 15 June 2014

c# - Regex: Find pagenumber from partial matching urls -



c# - Regex: Find pagenumber from partial matching urls -

as know, regex patterns create stomache turn first time see them (or 10th time since never went head first , learned it. quilty.). i'm reading upon it, since i'm on tight deadline i'll check here if can quicker , improve answer/explaination meanwhile.

i have url forum thread, , want scan through html , find lastly page thread.

so have 1 of next urls identifying thread in question:

https://www.somesite.com/forum/thread-93912* (absolute url thread) /forum/thread-93912 (relative url thread)

and want values (integers) appear straight (next path) after of above "partial" match in html-document.

so of next hrefs located anywhere in html-document (the doc represented single string):

https://www.somesite.com/forum/thread-93912/34 https://www.somesite.com/forum/thread-93912/34/morestuffhere/whatevs /forum/thread-93912/34 /forum/thread-93912/34/somethingheretoo

i want extract number 34 (only 34), can parse int.

edit

okay, create simpler:

say have html in htmlstring, , in string want find all numbers x appear after inputstring /forum/thread-93912.

these appear in htmlstring, , want extract numbers:

thread-93912/34 thread-93912/14 thread-93912/84 thread-93912/64 thread-93912/4

you don't need regex. utilize system.uri.segments

uri url = new uri("your url here"); console.writeline(url.segments[4]);

c# regex

No comments:

Post a Comment