javascript - Regex - match from N-th occurence of a character till end of string -


going mad here :) because must simple , can't crack it.

example:

htz_2015_cs_ss5_cncenter_1020x200_as2_10k.html htz_2015_cs_ss5_cncenter_1020x200_as2_10k.swf htz_2015_cs_ss5_cncenter_1500x1000_160k_w1020.jpg 
  • match 6th "_" (underscore character), select , follows, till end of string
  • replace nothing (basically delete 6th underscore end of string)

i using sublime text text editing, find/replace function if necessary use online tool (any suggestions?). these might have guessed banner file names regularly need modify, hundreds of them @ time.

many thanks!

p.s. can write simple js maybe option if must be.

if sure there @ least 6 _ in string :

   src.match (/^((?:[^_]*_){5}[^_]*)(_[^]*)$/)[1] 

'htz_2015_cs_ss5_cncenter_1020x200_as2_10k.html'.match (/^((?:[^]*){5}[^]*)([^]*)$/)[1] == 'htz_2015_cs_ss5_cncenter_1020x200'

otherwise use :

  (src.match (/^((?:[^_]*_){5}[^_]*)(_[^]*)$/) || [,src])[1] 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -