this is an at command"; if ($var =...">

The pattern matches a hyphen.

I have a piece of Perl code (pattern matching) for example

$var = "<AT>this is an at command</AT>";

if ($var =~ /<AT>([\s\w]*)<\/AT>/i)
{
    print "Matched in AT command\n";
    print "$var\n\n";
}

It works great if the content inbetween tags does not have Hyphen. It does not work if between the lines at the tags, inserted a hyphen ... <AT>this is an at-command</AT>.

Is it possible to commit this regular expression even if a hyphen is also inserted?

help me pls

Sentil

+3
source share
5 answers

Use \ S instead of \ w.

if ($var =~ /<AT>([\s\S]*)<\/AT>/i) {
+1
source

Character class

Your template contains this subpattern:

[\s\w]*

[…] - . - [aeiou] . [^…] . [^aeiou] , .

\s ; \w . .

* - Regex: [01-12] ?

+8

char :

if ($var =~ /<AT>([\s\w-]*)<\/AT>/i)

, /, , /:

if ($var =~m{<AT>([\s\w-]*)</AT>}i)
+4

,

if ($var =~ /<AT>((?:(?!<AT>).)*)<\/AT>/i)

.

0

, [\ s\w -] * ( codaddict).

, lookahead, ( " , , " ), :

if ($var =~ /<AT>([^<]*)(?=<\/AT>)/i)

[^ <] " ( ), " < ".

lookbehind:

if ($var =~ (?<=/<AT>)([^<]*)(?=<\/AT>)/i)

( , , ), lex/yacc.

0

Source: https://habr.com/ru/post/1760516/


All Articles