Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE's to match a set of strings..Need help.

Status
Not open for further replies.

neocode

Programmer
Nov 17, 2001
1
US
Hey,
I need help in the following. I need a reg ex to match the following set of lines:

liblaser2 8 80 346
lp "no print credits - denied"
"-18 + 500 = 482" (fdihdz 031877)

There are other lines too but are similar to these lines.
I have tried:
($printer, $rest) = $stats =~ /(\w{2,12})\s(\d{1,2}\s\d{1,4}\s\-?\d{1,4})/;

$printer saves thename of the printer (liblaser, lp etc) and $rest saves everything else. The reg ex that I have can't deal with quotes.

Can anyone come up with a reg ex that can save the printer name (if present)in $printer and save the rest of the string in $rest? and If string starts off with a quote. save it in either $printer or $rest.??

Thanks in advance.
 
so the printer name has two possible locations: as the first word on the line, or, as the first word following a set of quotation marks. something similar to this would probly work:
[tt]
$stats =~ m~^(\".*?\"\s)?(\w*?)(\s+.*)$~;
$printer = $2;
$rest = $1 . ' ' . $3;
[/tt]
i don't know how you'd want the format of $rest to be, so i just did whatever. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top