extract substring with regex that contains a period -


i have list of names here

apple.fruit appleorder2.fruit orange.fruit 

i want extrat fruit name

expected

apple apple orange 

i have regex (.*)((order)|(\.fruit))

that returns @ position one,

apple appleorder2 orange 

i think \. messing alternation character because when did test using

(.*)((order)|(ge)) 

the alternation works fine returning @ position 1

empty apple oran 

perl being used

use lazy quantifier:

(.*?)(order|\.fruit) 

in regex, .* first matches entire string, backtracks 1 character @ time until alternation order|\.fruit matches. since that's case after 6 backtracks already, regex engine never gets point might find other, earlier alternative. solution: tell regex engine match few characters possible adding ? quantifier.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -