Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: perlre inverse check for several patterns

by averlon (Sexton)
on Jun 02, 2023 at 14:47 UTC ( [id://11152612]=note: print w/replies, xml ) Need Help??


in reply to Re: perlre inverse check for several patterns
in thread perlre inverse check for several patterns

Hi hippo!

no, it is not HTML. It is some interface using some formatting strings like (!!like!!) HTML. But unfotunately the interface crashes if some "<>" strings are included which do not match the allowed formatting strings.

The strings I process are lines from logfiles. Unfortunately some of these lines include "<xxx>" strings. This brings the interface I use into trouble. So I need to filter them out.

I meanwhile found out I get a "true" if I use the following code:

$av_tmp_STRING = "xxx<pre>xxx<www>xxx<strong>xxx"; if ( $av_tmp_STRING =~ m/<(?!strong>)(?!pre)/ ) { #do something with the string which contains wrong patterns }

Still testing if it really works

But anyhow. I will keep the example in mind for other use!

Thanks

Regards Kallewirsch

Replies are listed 'Best First'.
Re^3: perlre inverse check for several patterns
by haukex (Archbishop) on Jun 03, 2023 at 07:48 UTC
    no, it is not HTML. It is some interface using some formatting strings like (!!like!!) HTML. But unfotunately the interface crashes if some "<>" strings are included which do not match the allowed formatting strings.

    Could you enlighten us as to what exactly this format is and perhaps provide a more representative sample? Also, is it not feasible to fix the crashes in the interface?

      Hi haukex,

      in my private environment I follow some logfiles by File::Tail and report lines of interest to some TELEGRAM Channel via WWW::Telegram::BotAPI. The TELEGRAM API knows some forms of limited formatting of the string to send. One of the formatting options is called "HTML", although there are only 3 or 4 fomatting tags similar to the HTML tags.

      One e.g. is:

      <strong>xxx</strong>

      The example I gave is very much the same as a real logfile line. But if you wish I can give a real example:

      $av_tmp_LINE = "Jun 3 23:20:05 f42252s5 postfix/pickup[204714]: E1E63 +A045C: uid=33 from=<www-data>" $av_tmp_STRING = "Logfile: " . "<strong>" . $av_obj_TMP->{input} . "</ +strong>" . " " . $av_tmp_LINE;

      Now the string $av_tmp_STRING should be sent to the TELEGRAM Channel using "HTML" formatting. But unfotunately inside the string there is the "<www-data>" which looks like a formatting string, but is unsupported.

      This causes the module to abort, although eval is used.

      Messge:

      "Request failed with error 'ERROR: code 400: Bad Request: can't parse +entities: Unsupported start tag "www" at byte offset 53 at /usr/share +/perl5/WWW/Telegram/BotAPI.pm line 224. WWW::Telegram::BotAPI::api_re +quest(undef, undef, HASH(0x55e57ea8da98)) called at ./av_perlre.pl li +ne 268 eval {...} called at ./av_perlre.pl line 266 ', but I'm still +alive! at ./av_perlre.pl line 266."

      Since I am not a very experience programmer, I probably have done something wrong. I have already reported the issue to the module creator.

      My Code:

      $av_std_RETVAL = eval { $av_obj_TGRAM->sendMessage ( { chat_id => $av_loc_tgram_CHATID, text => $av_tmp_STRING, disable_notification => 'false', parse_mode => 'HTML', } ) } or warn "Request failed with error '$@', but I'm still alive!";

      This is according to the docu. The docu says, by using eval the way above, the program will not abort - but it does.

      Regards Kallewirsch

        My fault!

        I ran the test-script in debug mode. The debug stopped and I assumed this aborted the script - but did not!

        The eval works

        Anyhow! I have to find a way to catch the unsupported formatting codes and eliminate them. I guess the regex will do! I will see!

        Regards Kallewirsch
Re^3: perlre inverse check for several patterns
by LanX (Saint) on Jun 05, 2023 at 12:51 UTC
    > it is not HTML. It is some interface using some formatting strings like (!!like!!) HTML. But unfotunately the interface crashes if some "<>" strings are included which do not match the allowed formatting strings.

    So what's wrong with tybalt89's approach?

    see Re: perlre inverse check for several patterns

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11152612]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found