Re: Expression problem
- From: Ric <antispam@xxxxxxxxxxxxxx>
- Date: Mon, 27 Nov 2006 22:50:27 +0100
You need to post at least one of the lines you read from your text file.
You should name the values you would like to have extracted.
example line: yesterday 12:30 hans:went:home
var1 should contain: 12:20
var2 should contain: went
this is much faster and precise than explaining something in a huge
block of text
K.J. 44 schrieb:
I have the two following regular expressions. I am not very good at.
writing these yet. I am parsing some logs looking for some key words,
then taking the text after them.
if ($details[$i] =~ /\bworkstation\b\bname:\b\s\b[0-9A-Za-z_\-]+\b/i) {
($nothing, $hostName[$i]) = split(/:/, $&);
}
if ($details[$i] =~ /\buser\b\bname:\b\w+/i) {
print("The username is: $&");
($nothing, $username[$i]) = split(/:/, $&);
}
The $details array is read in from a text file and this works fine.
What I want to do is search the $details text for certain key words,
then take the text right after. The first if statement
Find the word Workstation followed by a space followed by name:
followed by a space followed by a string of characters including word
characters and hyphens. if the match is found, take only the text
after the : as the workstation name.
The second part is along the same lines for username.
Find the word user followed a space followed by the word name: followed
by a space followed by a string of word characters. Split at the : as
the username found.
These do not seem to be finding matches when I can see them in the log
file. Where am I messing up?
Thanks.
- References:
- Expression problem
- From: K.J. 44
- Expression problem
- Prev by Date: Expression problem
- Next by Date: Re: Expression problem
- Previous by thread: Expression problem
- Next by thread: Re: Expression problem
- Index(es):
Relevant Pages
|