python - Returning the words after the first hypen is found -


suppose have list of items - ['test_item_a-engine-blade', 'test_item_a-engine-part-initial', 'test_prop_prep-default-set']

and trying grab words after first hypen found such result should follows:

  • test_item_a-engine-blade => engine_blade
  • test_item_a-engine-part-initial => engine_part_initial
  • test_prop_prep-default-set => default_set

i tried re.sub("[^a-z\d]", "", <my string>.split('-', 1)) seems presents me words before string...

you can use split maximum number of one.

something.split('-', maxsplit=1) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -