regex: remove file ext

From: picaza (icaza_at_earthlink.net)
Date: 10/29/04


Date: Fri, 29 Oct 2004 20:54:01 GMT

hi,
i am trying to lope off the extention of filenames as i read them w/ a
regex. seems like it should be easy but i cant get the regex to work.
i would like to use "\\.\\w$" or "\\.\\S$" but they dont work.
what does work is
"\\...$" or "\\.nc$"
but these dont offer the flexibility i want. the snippet of code follows
thanks,
peter.
+++++++++++++++
/ the regex is ".\w$" a dot followed by a word at the end of the str
Pattern fileExtRegEx = Pattern.compile("\\.\\w$");
Matcher FileExtMatcher;
while ((str = in.readLine()) != null)
     {
     FileExtMatcher = fileExtRegEx.matcher(str);
     str = FileExtMatcher.replaceAll("");
     allNames.add(str);
     }
++++++++++++



Relevant Pages

  • Re: did I get greedy quantifiers wrong ?
    ... My initial understanding was that .*i would match all the way till last char i. ... > regex to match. ... > $str = mississippi; ...
    (perl.beginners)
  • Re: Find & Replace in Multi-Megabyte Strings
    ... REGEX Avery should be your name! ... Following example takes 20 seconds for the 6 replacements. ... Dim str$, arrPat, arrRep ... > String processing in VBA is very slow when strings are large (1-500 ...
    (microsoft.public.excel.programming)
  • Re: two regexs
    ... I would like to match each value from @str with only one regex. ... informally-specified bug-ridden slow implementation of half of Common Lisp. ...
    (comp.lang.perl.misc)
  • Re: Can I find a size of font in the current element?
    ... > Should I just split the strVal by RegEx and convert to Number? ... str = new String; ... I don't even think you need the explicit conversion. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: two regexs
    ... gbacon@hiwaay.net (Greg Bacon) wrote: ... I would like to match each value from @str with only one regex. ...
    (comp.lang.perl.misc)