[问题]一个关于perl 的正则表达式的问题

软件和网站开发以及相关技术探讨
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

Re: [问题]一个关于perl 的正则表达式的问题

#16

帖子 banban » 2008-08-05 21:46

kofshower 写了: 之后的依次是$2,$3,$4,$5.
我是从ruby这们语法和perl和类似的语言想到的.后来看了perl handbook.
我本身不会perl
后面的几个$是要有(),即新的匹配模式才会生成的。每个满足匹配模式的子字符串才会储存到$2等里面的。
不过,多谢了,你不必浪费时间在我这种问题上的,还要害你再查别的资料,不好意思阿……
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#17

帖子 banban » 2008-08-05 21:49

xiooli 写了: :em65 ,你们老师肯定是perl饭咯?
我导师不是perl 饭,因为我们方向有一部分是要涉及到生物信息学的,perl 处理字符串的功能很强大,所以很适合作这方面的工作,老师才让我们学的。我的导师不会盲目地喜欢什么东西的……
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#18

帖子 kofshower » 2008-08-05 21:51

不用,我从ruby想到了perl.
如果真的去看perl语法和标准库,估计一个晚上就没了.
如我所想,语言是相通的,答案应该在标准库中.比如ruby对字符串处理的scan,扫描一个串,然后把结果iterate处理之后输出.

ps:如果你找到了答案,拜托贴出来下.我看看perl是怎么一回事的
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#19

帖子 banban » 2008-08-05 22:00

kofshower 写了:不用,我从ruby想到了perl.
如果真的去看perl语法和标准库,估计一个晚上就没了.
如我所想,语言是相通的,答案应该在标准库中.比如ruby对字符串处理的scan,扫描一个串,然后把结果iterate处理之后输出.

ps:如果你找到了答案,拜托贴出来下.我看看perl是怎么一回事的
恩,知道了。谢谢……
找到答案一定贴出来,不过,可能需要等等,呵呵……
heejun
帖子: 60
注册时间: 2006-05-01 12:29
来自: zju

#20

帖子 heejun » 2008-08-05 22:51

banban 写了:
heejun 写了:可以使用global match

代码: 全选

#!/usr/bin/perl
use strict;
use warnings;
my $data = "atggcagttggtacctaagcattdggtacccgtta"; 
my @match = $data =~ m/([atcgdu]{4}ggtacc)/g; 
print "$_\n" foreach @match;
agttggtacc
attdggtacc
but why?
碱基里面有d?
貌似结果不正确,我想要的结果是要显示几个字符串的,难道要用到多维数组?不对,维数又不能确定,容我想想……
给出输入以及预期结果
长度为10的子字符串这话嘛意思?
看前面几位仁兄的结果长度都不是10的
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#21

帖子 banban » 2008-08-06 8:35

heejun 写了:可以使用global match

代码: 全选

#!/usr/bin/perl
use strict;
use warnings;
my $data = "atggcagttggtacctaagcattdggtacccgtta"; 
my @match = $data =~ m/([atcgdu]{4}ggtacc)/g; 
print "$_\n" foreach @match;
agttggtacc
attdggtacc
but why?
碱基里面有d?
这个不好意思哦,应当是没有d的,是我当时输错了。就当没有就好了……
头像
Roots
帖子: 662
注册时间: 2005-08-17 19:20

#22

帖子 Roots » 2008-08-10 19:35

对生物很感兴趣,可惜没明白mm要表达的意思
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#23

帖子 banban » 2008-08-10 21:53

Roots 写了:对生物很感兴趣,可惜没明白mm要表达的意思
哦,这样阿。可能是我没说清楚。
总之,就是要把一段序列进行酶切,找出不同人上传的同一基因的不同序列的多态位点,最后找出探针。
明白了不? :em06
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

#24

帖子 xiooli » 2008-08-10 22:39

banban 写了:
Roots 写了:对生物很感兴趣,可惜没明白mm要表达的意思
哦,这样阿。可能是我没说清楚。
总之,就是要把一段序列进行酶切,找出不同人上传的同一基因的不同序列的多态位点,最后找出探针。
明白了不? :em06
说的太专业了,连我这个前生物工程系的都要晕半天。
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#25

帖子 kofshower » 2008-08-11 2:42

代码: 全选

#!/usr/bin/perl
use strict;
use warnings;
my $data = "atggcagttggtacctaagcattdggtacccgtta";
my @match = $data =~ m/([atcgdu]{4}ggtacc)/g;
print "$_\n" foreach @match; 
上面不是可以了么,
算是学习了,以前没有使用过perl的说,可是perl的语义太依赖上下文,不是很喜欢.
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#26

帖子 banban » 2008-08-11 7:49

xiooli 写了:说的太专业了,连我这个前生物工程系的都要晕半天。
可能是因为我是专业搞数量遗传的,分子方面的一些话说得还不是很标准阿,呵呵,请见谅了哦…… :oops:
头像
banban
帖子: 3340
注册时间: 2008-03-23 17:01

#27

帖子 banban » 2008-08-11 7:53

kofshower 写了:

代码: 全选

#!/usr/bin/perl
use strict;
use warnings;
my $data = "atggcagttggtacctaagcattdggtacccgtta";
my @match = $data =~ m/([atcgdu]{4}ggtacc)/g;
print "$_\n" foreach @match; 
上面不是可以了么,
算是学习了,以前没有使用过perl的说,可是perl的语义太依赖上下文,不是很喜欢.
果真是可以了,我第一次怎么执行结果不正确,我还以为这样写不对呢。呵呵。
我师兄是这么做的:
对于每一个序列,先酶切一次,然后把剩余的部分赋给一个新的变量,再把这个新的序列再酶切,这样就可以保存每一个满足条件的片段了。不过,偶觉得还是8楼的方法比较可取,所以师兄的方法我就不贴出来了,大家明白意思就可以了。
头像
kofshower
帖子: 1343
注册时间: 2007-03-13 11:23
联系:

#28

帖子 kofshower » 2008-08-11 12:36

恩,这样是对的,那个时候确认了一下,还以为问题已经结了.

代码: 全选

g 	Match globally, i.e. find all occurrences.
i 	Makes the search case-insensitive.
m 	If the string has new-line characters embedded within it, the metacharacters ^ and $ will not work correctly. This modifier tells Perl to treat this line as a multiple line.
o 	Only compile pattern once.
s 	The character . matches any character except a new line. This modifier treats this line as a single line, which allows . to match a new-line character.
x 	Allows white space in the expression. 
:oops:
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
头像
Roots
帖子: 662
注册时间: 2005-08-17 19:20

#29

帖子 Roots » 2008-08-11 21:29

抛了块砖,引出了块玉
wuchuanren
帖子: 99
注册时间: 2008-01-31 16:55

#30

帖子 wuchuanren » 2008-08-15 15:50

突然想起来,perl里面有个叫\G(具体需要查书……)的标签,是从上次匹配结束开始匹配。
用这个就可以了
回复