我可以在我的代码中将 Perl 正则表达式分成多行吗? [英] Can I break my Perl regex into multiple lines in my code?
问题描述
我只是想知道我是否能够分解我在 Perl 代码中的长正则表达式,以便将它写成多行?我只是希望可读性和紧凑性对于任何可能在完成后查看我的代码的人来说都是完整的.我正在寻找类似于在 Perl 中将字符串分解为多行的方式.例如:
I was just wondering if I am able to break up a long regular expression that I have in my Perl code so that it is written over several lines? I just want the readability and compactness to be intact for anyone that might view my code after its completion. I am looking for something analagous to the way in which strings are broken up over several lines in Perl. For example:
print "This is a string that is ". #1st line
"very long, so it is on 2 lines!"; #2nd line
# prints = "This is a string that is very long, so it is on 2 lines!"
我不知道如何用正则表达式来做到这一点,因为它不使用引号.如果我按回车,我猜它会在我的正则表达式中放置一个新行字符,使其出错.我想做一些类似的事情:
I am not sure how to do this with a regex since it does not use quotes. If I press enter I am guessing it will put a new line character in my regex making it erroneous. I would like to do something along the lines of:
if($variable_1 = /abcde_abcde_abdcae_adafdf_ #1st regex line
abscd_casdf_asdfd_....asdfaf/){ #regex continued
# do something
} # regex looking for pattern = abcde_abcde_abdcae_adafdf_abscd_casdf_asdfd_....asdfaf
推荐答案
是的,请参阅 /x 修饰符
在 perlre 手册页中.
Yep, see the /x modifier
in the perlre man page.
这篇关于我可以在我的代码中将 Perl 正则表达式分成多行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!