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

Re: regex optional word match

by moritz (Cardinal)
on Jul 26, 2012 at 09:43 UTC ( #983811=note: print w/replies, xml ) Need Help??


in reply to Parsind data in xlsx

What data do you need to extract? And what have you tried, what problems did you have?

Replies are listed 'Best First'.
Re^2: regex optional word match
by Rahul Gupta (Sexton) on Jul 26, 2012 at 10:03 UTC
    I have tried this regular expression $_ =~ m/^REMOTE\s+\[(.*?)\]\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+\[(.*?)\]\s+(.*?)sec\s+(.*)MBytes\s+(.*)Mbits\/sec
    . it gives data from both strings.But <cd> String1:"REMOTE Mon Jul 16 21:49:33 2012 @@ ueh1 TNT 20490 1916 0.0- 1.0 sec 0.33 MBytes 2.74 Mbits/sec 6.056 ms 0/ 233 (0%)"; </c>having two values in last 6.056 ms and 0/ 233(0%) i have to make them optional. Please help me in this problem Thanx
        hi,
        I have one array with 2 Strings:
        String1: "REMOTE [Mon Jul 16 21:49:33 2012] @@ [ueh1] [TNT] [2049 +0] [1916] 0.0- 1.0 sec 0.33 MBytes 2.74 Mbits/sec 6.056 ms 0/ + 233 (0%)". String2: "REMOTE [Mon Jul 16 21:49:34 2012] @@ [pdn1] [SSH] [2049 +9] [3] 1.0- 2.0 sec 0.34 MBytes 2.86 Mbits/sec".
        In "String1" I have two extra values that is "6.056 ms" and "0/ 233 (0%)" rest are same in both string; I tried this regex: m/^REMOTE\s+\[(.*?)\]\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+\[(.*?)\]\s+(.*?)sec\s+(.*)MBytes\s+(.*)Mbits\/sec
        but need to add the above mentioned two values of String1 in regex and make them optional so that both condition gets passed and last values stored in $10, $11.
        Can anyone help me?
        Thanks in advance

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983811]
help
Chatterbox?
[jedikaiti]: Greetings, Salutations, and all that Jazz
[Perl300]: ok, and for future if I want to use local box for something similar, then will Email::Sender:: Simple be a good choice?
[1nickt]: It's a framework that allows you to specify the Transport agent to whatever you want. You could even write your own.
[1nickt]: Perl300 More doc
[hippo]: In that case, use Net::SMTPS and also encrypt your content before you send it eg. with Crypt::GPG

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2017-10-17 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (234 votes). Check out past polls.

    Notices?