.net - Regex - Match Last Occurance -


i have text file full of names, want match them via regex.

each name ends following text: fsa fwb fcc, eg:

">dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc 

i want use following expression match names:

""">.+?""fsa fwb fcc" 

aka match text "> fsa fwb fcc, can parse excess matched myself.

however "> occurs throughout file, starts matching earlier. have wondered how match last occurance of something, in case, ">, end specified.

thanks all, stan.

description

it looks you're ending string literally fsa fwb fcc, , beginning of substring you're interested in starts directly after last "> before end string.

this expression will:

  • find substring between last "> , next fsa fwb fcc

">((?:(?!">).)*)fsa\sfwb\sfcc

enter image description here

live demo

sample text

">sometext">a dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc ">sometext">b dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc ">sometext">c dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc 

matches found:

[0][0] = ">a dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [0][1] = dave smith\u0012\/a>\u0012\/div>\u0012div class=\"  [1][0] = ">b dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [1][1] = b dave smith\u0012\/a>\u0012\/div>\u0012div class=\"  [2][0] = ">c dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [2][1] = c dave smith\u0012\/a>\u0012\/div>\u0012div class=\" 

or

if want go further , capture last "> through \u0012 before fsa fwb fcc ... i.e. actual name , not markup text, have @ expression

">((?:(?!">).)*?)\\u0012(?:(?!">).)*fsa\sfwb\sfcc

enter image description here

live demo

sample text

">sometext">a dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc ">sometext">b dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc ">sometext">c dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc 

matches found

[0][0] = ">a dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [0][1] = dave smith  [1][0] = ">b dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [1][1] = b dave smith  [2][0] = ">c dave smith\u0012\/a>\u0012\/div>\u0012div class=\"fsa fwb fcc [2][1] = c dave smith 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -