logo
Tags down

shadow

match array to multiple regex (from array)


By : Sjele
Date : October 15 2020, 08:10 AM
it fixes the issue I have an array with Strings, let´s say , you can put the regex as a string. This would only return Schnitzel
code :
$data = @(
"Haus",
"Maus",
"Laus",
"Schnitzel",
"Elefant"
)

$Regex = '.*Schnitzel.*'

$test = $data | ? { $_ -match $Regex }

Write-Host $test
$Regex = '.*Schnitzel.*|.*Maus.*'
$Regex = '.*Schnitzel.*|.*aus.*'
$RegexArray = @(
    '.*Schnitzel.*',
    '.*Maus.*'
)

$Regex = $RegexArray -join '|'

$test = $data | ? { $_ -match $Regex }


Share : facebook icon twitter icon

perl: match multi-word regex items from array in a text file, multiple times


By : rich love
Date : March 29 2020, 07:55 AM
like below fixes the issue OK - so I've changed things to hopefully better deal with the problem.
I tried the words you want to match in the original file, and found no occurrences, so I randomly interspersed them through the file to give some output:
code :
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $file1 =("in gewissem Sinne Herr Geißler, in gewissen Fällen geehrten Damen in gewissen Fällen nicht nur hier im Saal sondern auch an den Bildschirmen! Wir möchte gern die Diskussion über die Schnellfahrstrecke Wendlingen-Ulm – und Herr Geißler, um auch da für Klarheit zu sorgen: Wenn wir in gewissen Fällen oder Schnellfahrstrecke reden, meinen wir dasselbe – diese Diskussion gewiß nicht einem Überblick beginnen, in gewissen Fällen informiert, warum wir diese in gewissen Fällen vorsehen, was der verkehrliche Vorteil und der verkehrliche Nutzen ist, und darüber hinaus natürlich soll ein Überblick gegeben werden, warum sie genau so geplant und ausgeführt wird, wie sie hier gewiß nicht");

# my @input1 = split('\s+', $file1);
# print Dumper \@input1;
my @input2 =('in gewissem Sinne', 'in gewissen Fällen', 'gewiß nicht', 'das weiß ich ganz gewiß');
# my @input2 = split('\s+', $file2);

my %hash;
foreach my $line (@input2){
    while ($file1 =~ m/$line/g){
    $hash{$line}++;
    }       
}

print Dumper \%hash;
$VAR1 = {
          'gewiß nicht' => 2,
          'in gewissem Sinne' => 1,
          'in gewissen Fällen' => 5
        };

how to store multiple match words in an array in php regex?


By : user2247729
Date : March 29 2020, 07:55 AM
I wish did fix the issue. i want to match different words of an html page in php like this & but have problem in these words are in same sentence!!
code :
$html = <<<EOF
    write('A')</script>
    write('B')</script>
    write('C')</script>
    write('D')</script>
    write('E')</script>

    write(33453)</script>
    write(6987)</script>
    write(4544)</script>
    write(345)</script>
    write(7876)</script>
EOF;

preg_match_all('~write\(\'([A-Z])\'\)</script>~', $html, $match1);
preg_match_all('~write\(([0-9]+)\)</script>~', $html, $match2);

foreach ($match1[1] as $i => $char)
    echo "$char-{$match2[1][$i]}\n";

javascript regex match on array to find multiple items


By : swarnimmalik
Date : March 29 2020, 07:55 AM
hop of those help? You don't even need RegEx for this, you can simply use Array.prototype.filter, like this
code :
console.log(myArray.filter(function(currentItem) {
    return currentItem.toLowerCase().indexOf("mo") !== -1;
}));
# [ 'move', 'mouse', 'mountain' ]
Object.defineProperty(Array.prototype, "MatchInArray", {
    enumerable: false,
    value: function(value) {
        return this.filter(function(currentItem) {
            return currentItem.match(value);
        });
    }
});

PHP regex match multiple tags within a string and add to array


By : Michal Kokršpaněl
Date : March 29 2020, 07:55 AM
wish helps you You can use this
preg_match_all('/(.*?)<\/item>/',$content,$matches);
code :
 Array
 (
    [0] => Array
    (
        [0] => <item>foo bar</item>
        [1] => <item>foo bar</item>
    )

[1] => Array
    (
        [0] => foo bar
        [1] => foo bar
    )

)

Php:Regex-How to extract multiple portions of match and store it in an array?


By : Lis Custodio
Date : March 29 2020, 07:55 AM
I wish this help you I have a page with the following code:- , Split The full String By:
code :
/<ul.*?>/m
/<i>(.*?)<\/i>/m
<?php

$re = '/<ul.*?>/m';
$re1 = '/<i>(.*?)<\/i>/m';
$str = '<ul class="food">
<li>
<i>Bread and Butter</i>
</li>
<li>
<i>Cheese</i>
</li>
<li>
<i>Milk</i>
</li>
</ul>
<ul class="fruits">
<li>
<i>Apple</i>
</li>
<li>
<i>Mango</i>
</li>
<li>
<i>Strawberry</i>
</li>
</ul>';

$list=preg_split($re,$str);
for($i=1;$i<count($list);$i++)
{
    preg_match_all($re1, $list[$i], $matches);
    print_r($matches[1]);
}
?>
Array
(
    [0] => Bread and Butter
    [1] => Cheese
    [2] => Milk
)
Array
(
    [0] => Apple
    [1] => Mango
    [2] => Strawberry
)
shadow
Privacy Policy - Terms - Contact Us © voile276.org