Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Regex, extracting stuff from the middle of a line

by perlNinny (Beadle)
on Aug 03, 2006 at 19:13 UTC ( [id://565533]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using a regex function from a hash
in thread Using a regex function from a hash

Messed up my question on the regex thing. Here is some example lines:

Created by a.buncha.stuff.I.dont.want\GeorgeO at the parker inn
date : 06-Aug-06:22.34.01 buncahstuffIdon'twant
Created by a.buncha.stuff.I.dont.want\7of9 at the parker inn
date : 06-Jan-06:22.34.01 buncahstuffIdon'twant

Please get me:
GeorgeO
06-Aug-06:22.34.01
7of9
06-Jan-06:22.34.01

2006-08-03 Moved and retitled by GrandFather, as per Monastery guidelines
Original title: 'Regex, extracting stuff from the middle of a line'

  • Comment on Re^3: Regex, extracting stuff from the middle of a line

Replies are listed 'Best First'.
Re: Re^3: Regex, extracting stuff from the middle of a line
by ikegami (Patriarch) on Aug 03, 2006 at 19:29 UTC

    Your requirements are very vague.

    • You didn't specify which components are constant and which are not. I assumed "\" and "date : " are constant.
    • You didn't specify of which chars the variable parts could be made. I assumed what is represented by "GeorgeO" could contain spaces (which required specifying " at the parker inn"),
    • You didn't specufy from where the lines came. I assumed a file handle.
    • You didn't specify what to do with the extracted values. I print them.
    while (<$fh>) { print("$1\n") if /\\(.*?) at the parker inn$/ or /^date : (\S+)/; }
Re: Re^3: Regex, extracting stuff from the middle of a line
by Fletch (Bishop) on Aug 03, 2006 at 19:29 UTC

    And your code that's not working looks like . . .?

    Show some effort of your own before submitting work requests. See How (Not) To Ask A Question.

    Update: Oop, didn't realize this was a followup to a prior question.

    Probably because it was exceedingly vague and offered no context or indication otherwise, so the how-not-to-ask-ing's still relevant.

Re: Re^3: Regex, extracting stuff from the middle of a line
by sh1tn (Priest) on Aug 03, 2006 at 19:28 UTC
    You should escape the special '\' symbol:
    m|\\(\w+)| and print $1, "\n";
    For the date/time:
    m|:\s+(\S+)| and print $1, "\n";
    See perlre


Re: Re^3: Regex, extracting stuff from the middle of a line
by swampyankee (Parson) on Aug 03, 2006 at 20:38 UTC

    While ikegami said pretty much everything I wanted to say, I suggest that if you can come up with a set of explicit rules for what you want removed or, conversely, kept, the code will be easy (perhaps not the most elegant possible).

    emc

    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.

    Groucho Marx

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://565533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found