首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

.split(/^|\s+/)和.split(/s+/)之间的差异

.split(/^|\s+/)和.split(/s+/)之间的差异在于正则表达式的不同。

.split(/^|\s+/)使用的正则表达式是/^|\s+/,其中^表示匹配字符串的开头,\s表示匹配任意空白字符(包括空格、制表符、换行符等),+表示匹配前面的元素一次或多次。所以这个正则表达式的意思是以字符串开头或者匹配任意空白字符作为分隔符进行分割。

.split(/s+/)使用的正则表达式是/s+/,其中\s表示匹配任意空白字符,+表示匹配前面的元素一次或多次。所以这个正则表达式的意思是匹配任意连续的空白字符作为分隔符进行分割。

总结起来,.split(/^|\s+/)会将字符串以开头或者任意空白字符作为分隔符进行分割,而.split(/s+/)会将字符串以任意连续的空白字符作为分隔符进行分割。

这两种方法的差异在于分隔符的选择,根据具体的需求选择适合的方法进行字符串分割。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • Sun Grid Engine 大规模集群监控

    #!/usr/bin/perl #!/bin/bash ## 最近查看队列使用情况 发现如下问题,用户使用SGE 集群的时候内存溢出 ## 此程序用于查看SGE (Sun Grid Engine) 整体集群监控 ##仅以此程序,帮助大家查看 自己任务状态,以免被杀!此工具归BGI所有,祝大家工作愉快! =head1 Name sge_cluster_queue.pl  -- choose the queue observation =head1 Description This program can choose the  bmk queue observation  1) look for the  queue  jobs operation and who is working state 2) find the jobs number total test number,and the user over mem jobs,Jobs-ID,detailed mem \ 3) statistics total use mem =head1 Version   Author: Li linji, lilinji@genomics.cn    Version: 1.0,  Date: 2012-7-30 =head1 Usage   --queue  set  you want  look up queue (defined general.q)   --mem    set  Use full details  queue Jobs and mem (check  over_mem,and jods-ID)   --s      set  Task sort by (name,job,vf,mem && must set --mem)##defined name   --t      set  Task state information  (defined run)   --help    output help information to screen =head1 Exmple ./sge_cluster_queue.pl    perl sge_cluster_queue.pl perl sge_cluster_queue.pl  -queue general.q perl sge_cluster_queue.pl  -queue general.q -mem perl sge_cluster_queue.pl  -queue general.q -mem -s vf =cut use Getopt::Long; use FindBin qw($Bin $Script); use File::Basename qw(basename dirname); use Data::Dumper; my $Sort||="name"; my $St||="r"; my ($help,$mem); $queue_search ||= "general.q"; GetOptions(     "help"=>\$help,     "queue=s"=>\$queue_search,     "mem"=>\$mem,     "s=s"=>\$Sort,     "t=s"=>\$St, ); die `pod2text $0` if ($Help); if ($Sort eq "1") {     $Sort="name"; }elsif($Sort  eq "2"){     $Sort="job"; }elsif($Sort eq "3"){     $Sort="vf"; }elsif($Sort  eq "4"){     $Sort="mem"; } if ($Sort ne "vf" && $Sort ne "mem" && $Sort ne "name" && $Sort ne "job" ) {     print STDERR <<SORt;     -s :        1 or name : sort by name (default)             2 or job :  sort by jobs number             3 or vf :  sort by vf (need  -m )             4 or mem : sort by mem (need  -m ) SORt         exit 0; if (!defined $mem &&  ($Sort eq "mem" || $Sort eq "vf" )) {     print STDERR <<SORt;           -mem : get mem info         -s

    01
    领券