[Tutor] regular expression matching a dot?

Kent Johnson kent37 at tds.net
Wed Oct 19 12:08:11 CEST 2005


Christian Meesters wrote:
> Hi
> 
> I've got the problem that I need to find a certain group of file names 
> within a lot of different file names. Those I want to match with a 
> regular expression are a bit peculiar since they all look like:
> 07SS.INF , 10SE.INF, 13SS.INF, 02BS.INF, 05SS.INF.
> Unfortunately there are similar file names that shouldn't be matched, 
> like:
> 01BE.INF, 02BS.INF
> Any other extension than 'INF' should also be skipped. (There are names 
> like 07SS.E00, wich I don't want to see matched.)
> So I tried the following pattern (using re):
> \d+[SS|SE]\.INF - as there should be at least one digit, the group 'SE' 
> or 'SS' followed by a dot and the extension 'INF'.

Use parentheses () for grouping. Brackets [] define a group of characters. Your re says to match
  \d+ one or more digits
  [SS|SE] exactly one of the characters S, |, E
  \.INF literal .INF

Since there are TWO characters S or E, nothing matches. Change the [] to () and it works.

Kent



More information about the Tutor mailing list