Johanna: Ersetzen

Hi!

ich möchte in einer Variable etwas durch nichts ersetzen.

Suchtext
wort2 oder wort1wort2

$variable =~ s/wort2//;

wie muss ich da wort1 unterbringen?

Danke!

  1. ich möchte in einer Variable etwas durch nichts ersetzen.

    Suchtext
    wort2 oder wort1wort2

    $variable =~ s/wort2//;

    wie muss ich da wort1 unterbringen?

    Das kann die perldoc
    oder selfhtml beantworten

    mfg Beat

    --
    ><o(((°>           ><o(((°>
       <°)))o><                     ><o(((°>o
    Der Valigator leibt diese Fische
    1. Hi!

      ich möchte in einer Variable etwas durch nichts ersetzen.

      Suchtext
      wort2 oder wort1wort2

      $variable =~ s/wort2//;

      wie muss ich da wort1 unterbringen?

      Das kann die perldoc
      oder selfhtml beantworten

      tut es leider nicht

      auf der selfhtml seite war ich vorher schon, bei perldoc finde ich nicht die passende Stelle

      ich hatte schon folgendes probiert, jedoch wird dann nichts ersetzt.
      $variable =~ s/(wort1)?wort2//;

      Danke!

      1. Hallo Johanna,

        $variable =~ s/(wort1)?wort2//;

        versuch mal
        $variable =~ s/(?:wort1)?wort2//;

        Lieben Gruß
        JOhnnY

        1. Hi!

          $variable =~ s/(wort1)?wort2//;
          versuch mal
          $variable =~ s/(?:wort1)?wort2//;

          damit wird auch nichts ersetzt

          psh% $text = "wort1wort2";
          psh% printf("%s\n", $text)
          wort1wort2
          psh% $text =~ s/(?:wort1)?wort2//;
          psh% printf("%s\n", $text)
          wort1wort2
          psh%

          Danke!

  2. ich möchte in einer Variable etwas durch nichts ersetzen.

    Suchtext
    wort2 oder wort1wort2

    $variable =~ s/wort2//;

    wie muss ich da wort1 unterbringen?

    Ich verstehe nicht was du genau willst. suchst du den Oder Operator

    my $variable = 'text wort1 oder wort2 und mehr text';  
    $variable =~ s/wort2|wort1//g;  
    print $variable;  
    
    

    Struppi.

    1. Hi!

      ich möchte in einer Variable etwas durch nichts ersetzen.

      Suchtext
      wort2 oder wort1wort2

      $variable =~ s/wort2//;

      wie muss ich da wort1 unterbringen?

      Ich verstehe nicht was du genau willst. suchst du den Oder Operator

      my $variable = 'text wort1 oder wort2 und mehr text';

      $variable =~ s/wort2|wort1//g;
      print $variable;

        
      nein, ich will das Wort "wort2" oder das Wort "wort1wort2" ersetzen  
        
      Beispiele:  
      "text text wort2" > "text text "  
      "text text wort1" > "text text wort1"  
      "text text wort1wort2" > "text text "  
      "text text wort1 wort2" > "text text wort1 "  
        
      ich suche ungefähr soetwas, jedoch funktioniert das nicht  
      psh% $text = "wort1wort2";  
      psh% printf("%s\n", $text)  
      wort1wort2  
      psh% $text =~ s/wort1wort2|wort2//;  
      eval error (Substitution pattern not terminated at (eval 64) line 1, <DATA> line 185.)!  
      eval error (syntax error at (eval 64) line 1, at EOF)!  
        
        
      Danke!
      
      1. Ich verstehe nicht was du genau willst. suchst du den Oder Operator

        my $variable = 'text wort1 oder wort2 und mehr text';

        $variable =~ s/wort2|wort1//g;
        print $variable;

        
        >   
        > nein, ich will das Wort "wort2" oder das Wort "wort1wort2" ersetzen  
          
        Naja, wie das geht habe ich dir gerade gezeigt.  
          
        Struppi.