Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Answer: How do I print only some letters of this string

( #19243=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > How do I print only some letters of this string contributed by jlistf

i see two ways to answer this question. you could use a regex: (assuming the data is in $_):
m/(\d{4}/\d{2}/\d{2}\s*?\d{2}:\d{2}:\d{2}\s*?$name\s*Communications Al +arm\s*Critical|Minor\s*?.{17})/; $data = $1;
that expression may need some debugging, but thats the basic idea. $name can be replaced by something to represent the N1B1,etcs. i don't know what that part of the data is so i'm not sure how to represent it in a regex. second option:
($date, $time, $name, $comm, $alarm, $severity, $data) = split ' ',$_, +7; $data = substr ($data,0,17);
again this might need a little tweaking, but thats the basic idea. there are other ways as well, but these are the two that popped into my head.

Comment on Answer: How do I print only some letters of this string
Select or Download Code
RE: Answer: How do I print only some letters of this string
by nuance (Hermit) on Jun 21, 2000 at 19:39 UTC

    I don't think this regular expression does what you think it does. You have not bounded that | term, so it splits your entire regular expression into two. Also you don't need all the stuff at the start since you aren't actually doing anything with it (storing it etc.)

    You could achieve your goal with:


    The (?: term groups without creating a back reference. The \s should not use non-greedy matching, using non-greedy matching here will include leading space in the 17 characters if there is more than one space separating the final two fields. Also we want at least one character at that position so + is better than *. The final field needs to be limited to 17 characters, but if there are less, your expression will fail instead of returing as many as it can find.


      good points all of them. i probably should have done a little more debugging on my answer, but i figured the gist would come across. you could also use ?<= instead of ?: but thats a minor detail.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-12-27 20:37 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (177 votes), past polls