Re: I need to extract an array from a scalar regex-wise ?



Uri Guttman wrote:


[please stop leading quoted text with spaces]

ordon Etly <get@xxxxxxxxxxx> writes:

Uri Guttman wrote:

Gordon Etly <get@xxxxxxxxxxx> writes:

Ok, so I mis-read. After re-reading it seems he just wants to
capture
the days of the week from the string, so the answer is simple:

you misread AGAIN.

No I didn't:

advice please wireless 802.11 on RH8 wrote:

> Let's say I want to extract all of the days of the week out
> of a scalar
...
> I want a regex/map/grep/etc (no iterative clauses PLEASE!)
> that yields:
>
> @days = qw( Monday Sunday Saturday Thursday Tuesday Wednesday )

He wanted the days in the string (presuming in the order they appear)
and ultimately stored into an array. My example fulfills this.

Code:
$_ =
'We went to the beach on Monday but it turned out that Sunday would
have been better. The weather report Saturday said no rain until
Thursday but I asked Tuesday (a trick!) and she said it rained
Wednesday.';

my @days = m#((?:mon|tues|wednes|thurs|fri|satur|sun)day)#gi;

print join(", ", @days);

the OP wanted the unique set of days which is why his post had a keys
on a dereferenced but incorrect hash ref. and he wanted it in one
expressions without external loops.


advice please wireless 802.11 on RH8 wrote:

> I'm also not crazy about the hash solution because order may
> be significant.

He never said "unique", all he said was he wanted to capture the
occurrences of days of the week in the string into an array. He never
said their couldn't be duplicates. He _did_ say that "order may be
significant", which to me is in line with capturing each occurrence of a
day of the week in the string (as they appear.)

also he got correct answers from other people (including myself) a

Actually your answer was based on the occurrences' being unique, a
requirement the OP never gave, so your answer imposes a limit the OP
most likely doesn't want, where as mine solution merely gets each
occurrence, in the _order_ they appear.

while back. try reading followups before posting another answer

This answer I gave in my last post was correct. It was also simple and
to the point. Maybe _you_ should read the original post more carefully.


--
G.Etly


.



Relevant Pages

  • Re: Regex Capture problem
    ... "learned" my regex using a freeware utility that had slightly different ... was trying to capture instead of. ... I have used Regex utilities before, so I understand the concepts of text ... Function RESub(str As String, SrchFor As String, ReplWith As String) As String ...
    (microsoft.public.excel.programming)
  • Re: SQL - Capture Specific Text and Copy to New Column/row
    ... The script is: ... Please advise of how I may capture only the date/time data. ... wildcard characters as characters in the string. ... by the Option Compare setting of the module. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Regular Expression Hangs
    ... You wouldn't need a regular expression to ... a single fixed string. ... Those patterns are defined by rules that are expressed in the ... will capture the following: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to get all repeated group with regular expression
    ... string, such as string '123456', i tried re.findall*, ... nature to all regx engine or only to Python? ... issues that I can perfectly understand why Python works the way it does, ... Yes, you are right, but this way findallcapture only the 'top' group. ...
    (comp.lang.python)
  • Re: Herfried K. Wagner - HELP!
    ... Where did you find the command string ... Private Sub StartRecording() ... mciSimpleSendString("open new type waveaudio alias capture") ...
    (microsoft.public.dotnet.languages.vb)