Re: Expression problem



Christian Winter <thepoet_nospam@xxxxxxxx> wrote:

So the first piece of code could be cut down to
if( $details[$i] =~ /\bworkstation\sname:\s([0-9A-Za-z_\-]+)/i )
{
$hostName[$i] = $1;
}

There's still room for improvement, like


adding an //x modifier, particularly if you are "not very good"
at grokking regexes:

if ( $details[$i] =~ /\bworkstation
\s
name:
\s
(
[0-9A-Za-z_-]+
)
/ix
)


e.g. removing A-Z from
the character class, as you are giving the /i modifier anyway,
so both upper and lowercase characters will be matched.


and removing the backslash. Hyphen is not meta in a character
class if it is first or last in the class.


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.



Relevant Pages

  • Re: 4E - Paladin Build
    ... I've left the history of my character open to create mystery. ... Constitution: 12(Constitution Modifier: +1) ... once per encounter as a free action, ... once per encounter as a standard action, 2 square radius ...
    (rec.games.frp.dnd)
  • Re: Detect if a KeyStroke is a real character or not.
    ... type the character produced by that KeyStroke. ... menu accelerator modifier, because getMenuShortcutKeyMasktells you. ... getMenuShortcutKeyMaskis a "real" character on my platform. ...
    (comp.lang.java.gui)
  • Re: regex matching conditionally
    ... one per string? ... I love when I learn a new tidbit! ... The /o modifier only applies if you have variables in the regular expression. ... character which means you want to match only a literal '.' ...
    (perl.beginners)
  • Re: Detect if a KeyStroke is a real character or not.
    ... John B. Matthews wrote on 18.02.2009 21:02: type the character produced by that KeyStroke. ... Similarly, I would not set a menuItem's accelerator to Meta-C: it might look familiar on my platform, but it would be awkward on others. ... As I said AltGr or Ctrl-Alt do the same thing on Windows. ... MacOS adds the "option" key for which I don't even know what the modifier value in Java would be. ...
    (comp.lang.java.gui)
  • Re: Search Question
    ... > dot matches any character. ... not unless you're following damian's advice to use the /s modifier ... Under normal circumstances it matches any character ...
    (comp.lang.perl.misc)