Skip to main content

regular expression

Find The extension of a file using Perl

Sanjeev Kumar Jaiswal's picture

My friend asked me how to extract the extension from the given list of files.
There can be many ways but I used one small and simple regular expression to solve his problem.

Regular Expression is : /(.*)\.(.*)/ or  /\.([^.]*)$/
Although it is not very effective and may consume lot of time if number of files will be huge, because it is using greedy search on the pattern two times. We can avoid it using look ahead and look behind features in Regular Expression.

But as of now I didn't find the best solution for it so posting my basic solution for time being and will post the more efficient regular expression, once I get it successfully.

Minimal Introduction on Regular Expression

Sanjeev Kumar Jaiswal's picture

Regular expression IllustrationMinimal basics on Regular Expression (Non-technical )

This article is for those who have graduated from Computer Science background or have basic knowledge of natural language processing concepts. I will not share any coding stuffs in this post and all basic rules with examples will be posted in next article.
 In our graduation time we had one paper called Theory of Automata which dealt with NFA, DFA etc. There we had used some magic/wildcard symbols to complete the expression. Like “^(a|b*)+ababa?cd$”  I know it looks nothing more than a junk to a common man but it does lots of such things which saves our time and effort in real life of programming world.   Whatever you saw, was nothing but a small example of regular expression.
Syndicate content