regular expression Help

Discussion in 'Perl Misc' started by jtripo, Mar 22, 2005.

  1. jtripo

    jtripo Guest

    I have the following text

    blah blah blah blah System Is Working blah blah blah blah

    I need a regular expression that will show true only if System Is
    Working is missing. Is there a way to do this?

    Thanks
    Jeff
     
    jtripo, Mar 22, 2005
    #1
    1. Advertising

  2. "jtripo" <> wrote in news:1111514057.175208.228670
    @l41g2000cwc.googlegroups.com:

    > I have the following text
    >
    > blah blah blah blah System Is Working blah blah blah blah
    >
    > I need a regular expression that will show true only if System Is
    > Working is missing. Is there a way to do this?


    Why this requirement?

    Why can't you use (untested):

    my $s = q{blah blah blah blah System Is Working blah blah blah blah};
    unless(index($s, q{System Is Working}) > -1) {
    # system is not working
    }

    Sinan
     
    A. Sinan Unur, Mar 22, 2005
    #2
    1. Advertising

  3. jtripo

    Jeff Guest

    jtripo wrote:
    > I have the following text
    >
    > blah blah blah blah System Is Working blah blah blah blah
    >
    > I need a regular expression that will show true only if System Is
    > Working is missing. Is there a way to do this?


    There's no doubt some ugliness you can create using negative lookahead
    or somesuch, but it would seem a lot easier and more maintainable to
    just do something like:

    unless ( $text =~ /System Is Working/ ) {
    # Do whatever you wanted to if 'System Is Working' was missing
    } else {
    # It's there, so do whatever....
    }

    ~Jeff
     
    Jeff, Mar 22, 2005
    #3
  4. jtripo <> wrote:
    > I have the following text
    >
    > blah blah blah blah System Is Working blah blah blah blah
    >
    > I need a regular expression that will show true only if System Is
    > Working is missing. Is there a way to do this?



    print "missing\n" unless /System Is Working/;

    or

    print "missing\n" if $_ !~ /System Is Working/;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 22, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand

    Regular Expression help...

    Anand, Jul 9, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,236
    Eric J. Roode
    Jul 9, 2003
  2. Eric B.
    Replies:
    1
    Views:
    435
    Jim Gibson
    Dec 17, 2004
  3. VSK
    Replies:
    2
    Views:
    2,336
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    863
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,998
    vforvikash
    Dec 29, 2008
Loading...

Share This Page