Re: Expression problem



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.

.



Relevant Pages

  • Re: How to properly manage a custom profile?
    ... username, just to give the spammers something devious to do. ... is no official standard for characters in a username - RFC0822, ... and 5322 all define the name as "locally interpreted string followed ... 'jdoe' with a person named John Doe. ...
    (comp.os.linux.setup)
  • regex: Nested quantifier ?. error! help
    ... I am trying to use regex to find a string where? ... and 10 characters, for instance the strings: ... Username 1092006871 does not exist. ...
    (microsoft.public.dotnet.framework)
  • String Manipulation
    ... if I had a string that looked like: ... "This user has a username of - brian hammer" ... "This user has a username of - Any Number Of Characters" ...
    (microsoft.public.dotnet.framework)
  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)