Re: Expression problem



"K.J. 44" <Holleran.Kevin@xxxxxxxxx> wrote:
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) {

About the only places that \b should be used are the beginning or end
of the regex or before or after something like ".*". Also, I don't see how
you can ever productively have more than one in a row, doing so is probably
exactly the same as having just one.

\b is a zero-width condition. So "tion\b\bname" can never match because
you are demanding that there is a n before the \b zero-width placeholder,
and an n after the \b zero-width placeholder, and if that is the case then
the conditions which define \b are not met. Similarly the \b in ":\b\s" is
impossible to ever match, as it has to have a non-word character on each
side which is what \b does not do. The \b in "\s\b[0-9A-Za-z_\-]" is
almost redundant--it just forbid the "-" from the character class from
being used, which I doubt is what you want.

....


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.

.... /\bworkstation name: ([-\w]+)/i ...

If you "space" you meant "white space", then turn my spaces into "\s"
(not "\b").


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.