.net - Regex to find first extension in OpenFileDialog filter string -
i want find first extension in list of exentions in openfiledialog
file filter string.
consider below example -
image files(*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif
text files (*.txt)|*.txt
for first case - if user tries save file without extension default want append .bmp
extension filename.
for second case - if user tries save file without extension default want append .txt
extension filename.
rather use regex split string, use split function suggested sysdragon - there no earthly reason why wouldn't this. once have second part of original string regex bmp
*.bmp;*.jpg;*.gif
1 , match.
^\|\*\.(\w{1,4});
simply put, says following:
- ^ start @ beginning of string
- \| find pipe character (the \ delimits because equivalent of or in regex)
- \* find single * character (again, delimited because * means 'zero or more repetitions' in regex)
- \. find single period (delimited because means 'any character' normally)
- (\w{1,4}) find @ least 1 , 4 alphanumeric characters. capturing group can obtain match object.
- ; find semi colon
i have arbitrarily chosen 1-4 alphanumeric characters can adjust suit needs, instance {3}
mean 'find three', [a-za-z]{1,3}
mean 'find @ least 1 , 3 matches letters a-z , a-z'.
since wanted first extension want amend pattern give extensions match collection. in fact regex simpler (but why return n matches when 1 do?) , i'll levae learning exercise :-)
Comments
Post a Comment