Go Back   SEQanswers > General

Similar Threads
Thread Thread Starter Forum Replies Last Post
INDEL searches! Bionewb Bioinformatics 5 02-26-2009 12:43 PM

Thread Tools
Old 07-18-2013, 11:26 AM   #1
Junior Member
Location: Ireland

Join Date: Mar 2013
Posts: 5
Default Regex Searches?


I've been at this problem for some time now and any adice would be great. I have a file as such: Peter..Bjorn,John..Mary,Paul..Simon,Jack..Steve,

I wrote the following code:
@array = $line =~ /([A-Za-z]+\.\.[A-Za-z]+\,[A-Za-z]+\.\.[A-Za-z]+)/g;

It gives me: Peter,..Bjorn,John..Mary Paul..Simon,Jack..Steve

What I really want it to give me is: Peter..Bjorn,John..Mary John..Mary,Paul..Simon Paul..SImon,Jack..Steve

Is there anyway to go about doing that? I tried a lookaround, but that didn't help much.


Last edited by anzdro; 07-18-2013 at 12:04 PM.
anzdro is offline   Reply With Quote
Old 07-18-2013, 01:31 PM   #2
Senior Member
Location: Boston area

Join Date: Nov 2007
Posts: 747

More compact regex are more readable; use /gi; and you can drop the extra a-z (i=ignore case)

Could you check your examples for typos -- that regex should NOT be generating the output you specify (your code is missing the join command anyhow that you must be referring to). And is it you just want the 2nd name pair duplicated? It would help if you underlined what is different between intended and obtained.

Also, please use the CODE formatting for your example & code -- much, MUCH easier to debug regex when in constant width font

Last edited by krobison; 07-18-2013 at 01:37 PM.
krobison is offline   Reply With Quote
Old 07-18-2013, 01:49 PM   #3
Registered Vendor
Location: Eugene, OR

Join Date: May 2013
Posts: 521

You want it to print out the first comma delimited bit, then print out two copies of each of the following comma delimited bits with a space between the copies, then print out a single copy of the last bit? That sounds difficult with a one-liner

In Perl I would

$current_line = "Peter..Bjorn,John..Mary,Paul..Simon,Jack..Steve,";
@line = split(",",$current_line);
print "$line[0],";
for ($x = 1; $x < (@line - 1); $x++) {
 print "$line[$x] $line[$x],";
print "$line[$x]\n";
I ran it and got Peter..Bjorn,John..Mary John..Mary,Paul..Simon Paul..Simon,Jack..Steve
Providing nextRAD genotyping and PacBio sequencing services.
SNPsaurus is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -8. The time now is 09:43 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO