MathGroup Archive 2010

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

Search the Archive

Re: StringCases matching on portions of sublist?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106703] Re: StringCases matching on portions of sublist?
  • From: Raffy <raffy at mac.com>
  • Date: Thu, 21 Jan 2010 04:55:14 -0500 (EST)
  • References: <hj6qfm$8rk$1@smc.vnet.net>

On Jan 20, 3:47 am, Jason Ledbetter <jasonbr... at gmail.com> wrote:
> Folk,
>
> I'm trying to write a function to narrow down some data by timestamp but I'm
> having some trouble getting this to work.
>
> My data is a list of lists with the first member of each sublist being a
> date stamp. I was hoping to use StringCases to match but I'm apparently
> missing something here.
>
> Example data is as follows:
>
> z={{"Thu Nov 19 12:09:23 GMT 2009", 7492, 0,
>   0}, {"Thu Jan 07 13:48:21 GMT 2010", 9225, 3,
>   0}, {"Thu Dec 17 09:30:52 GMT 2009", 8735, 1, 0}}
>
> I've tried the following:
>
> StringCases[z, {"*Nov",___}]
>
> which returns:
>
> String or list of strings expected at position 1 in StringCases. This makes
> sense to me.. so I tried:
>
> StringCases[z[[All,1]], ___~~Nov~~___]
>
> which returns:
>
> {{"Thu Nov 19 12:09:23 GMT 2009"}, {}, {}}
>
> How can this be modified to return the full sublist where the first element
> of the sublist matches a string pattern?
>
> -jbl

This would get the job done, assuming your timestamps are all well-
formed:

Pick[z, StringTake[z[[All, 1]], {5, 7}], "Nov"]

Otherwise:

Select[z, StringMatchQ[First[#], ___  ~~ "Nov" ~~ ___] &]  (although
I'd recommend a more specific pattern)


  • Prev by Date: Re: Pagination when transferring Mathematica docs to PDF
  • Next by Date: NotebookGet/Read/EvaluateSelection Issues
  • Previous by thread: Re: StringCases matching on portions of sublist?
  • Next by thread: Re: StringCases matching on portions of sublist?