Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Perl pattern matching options

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what the Perl pattern matching options are, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Brief introduction of Perl mode

The Perl pattern refers to the characters of a specific sequence found in the string, contained by the backslash: / def/ is the Perl pattern def. Its use, such as combining the function split, divides the string into multiple words with a Perl pattern: @ array=split (/ /, $line).

Perl pattern matching options

Option description

G matches all possible Perl schemas

I ignore case

M treats strings as multiple lines

O assign a value only once

S treats the string as a single line

X ignore whitespace in Perl mode

1. Match all possible Perl modes (g option)

@ matches= "balata" = ~ / .a / Gbomaches.com ("ba", "la", "ta")

Matching loops:

While ("balata" = ~ / .a / g) {

$match=$&

Print ("$match\ n")

}

The result is:

Ba

La

Ta

When option g is used, the function pos can be used to control the offset of the next match:

$offset=pos ($string)

Pos ($string) = $newoffset

2. Ignore case (I option) example

/ de/i matches de,dE,De and DE.

3. Treat a string as multiple lines (m option)

In this case, the ^ symbol matches the beginning of a string or the beginning of a new line; the $symbol matches the end of any line.

4. perform a variable replacement example only once

$var=1; $line=; while ($var

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report