MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Extract substrings using metacharacters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48432] Extract substrings using metacharacters
  • From: Marcus Stollsteimer <marcus314 at yahoo.com>
  • Date: Sat, 29 May 2004 03:06:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

I do not have much experience with Mathematica string functions,
so this may be trivial:

When I use a string pattern with metacharacters
(like the patterns used for StringMatchQ[] or FileNames[]),
is there a simple way to extract the substring that
matches the metacharacters?
(something similar to regular expressions and m// in perl?)

I have a lot of similar but different file names that I
read in with FileNames[pattern], and I would like to extract
the different parts.

At the moment I have the following workaround:

files = {"data040523.dat","data040527.dat","data040528.dat"};
Do[
  datestr = files[[i]] // StringDrop[#, StringLength["data"]]& // 
      StringDrop[#, -StringLength[".dat"]]&;
  Print[datestr],
  {i, 1, Length[files]}
]

I am looking for a function StringPatternTake[str,"data*.dat"]
that works like StringTake, but not with the positions, but
with patterns instead.

Regards,
Marcus

-- 
[...] Fasting is a big mistake. Particularly on an empty stomach.
   -- W. Allen


  • Prev by Date: RE: math kernel keeps trying to access an ip
  • Next by Date: Re: NSolve freezes on two polynomial equations
  • Previous by thread: Re: Number of roots from Solve?
  • Next by thread: checking accuracy with stepwise ode.