473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

help with regular expressions

for a program i'm makin I need to be able to analyze lines like the following one

1 waarschijnlijk neiging tot suikerziekte ccaggcccac ctggagactc

and split it up in a part that containes the number
a part that containes the text
and as a last part the dna sequence ccaggcccac ctggagactc

now i can do that with the following code

Expand|Select|Wrap|Line Numbers
  1. # haal de ziekte codes er uit
  2.         if($line =~ m/(\b[ctga]+\b)(.*)/)
  3.         {
  4.  
  5.             $part3 = $1.$2; 
  6.  
  7.             # haal het einde lijn teken eraf
  8.             chop $part3;
  9.  
  10.         }
  11.  
  12.         # haal het nummer en de naam uit de string
  13.         if($line =~ m/(\d+)(.*?)(\b[gtac]+\b)/)
  14.         {
  15.  
  16.                         # $1 = the numeric part, $2 the text
  17.             # nu maken we een hash met het nummer als keyword 
  18.             $ziektenaamhash{$1} = $2;
  19.  
  20.             # we maken ook een hash waarbij het nummer verwijst 
  21.             $ziektehash{$1} = $part3;
  22.  
  23.         }
but I'm not really happy with the $1.$2 part as it forces me to use the chop operation every time.
Is there a more efficient way to be split the lines in those parts or is my code just fine?
Dec 21 '07 #1
3 1138
KevinADC
4,059 Expert 2GB
just remove the \b parts from the capturing parenthesis:
Expand|Select|Wrap|Line Numbers
  1. if($line =~ m/\b([ctga]+)\b(.*)/)
and you shouldn't have to use chop;
Dec 21 '07 #2
just remove the \b parts from the capturing parenthesis:
Expand|Select|Wrap|Line Numbers
  1. if($line =~ m/\b([ctga]+)\b(.*)/)
and you shouldn't have to use chop;
I have to chop because when perl somehow adds a character after the concatenation and that screws up my searching expression when I'm trying to find what i found here in text file
Dec 21 '07 #3
KevinADC
4,059 Expert 2GB
I have to chop because when perl somehow adds a character after the concatenation and that screws up my searching expression when I'm trying to find what i found here in text file
if you are reading the lines in from a file you should just chomp the line before doing anything else to it to remove the newline from the end. Perl will not add any characters that are not already there.
Dec 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
5
by: Greg Vereschagin | last post by:
I'm trying to figure out a regular expression that will match the innermost tag and the contents in between. Specifically, the string that I am attempting to match looks as follows: ...
2
by: news.microsoft.com | last post by:
I need help design a reg exp. I am parsing an html file to get the input values, here is one example <input VALUE="Staff Writer" size=60 type="text" name="author"> Can I grab the value "Staff...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: Zach | last post by:
I'm writing an app which is going to rely extremely heavily on the usage of regular expressions. I'm reading the docs but having trouble wrapping my head around some of this since it's all fairly...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
9
by: Rene | last post by:
I'm trying to basically remove chunks of html from a page but I must not be doing my regular expression correctly. What i'm trying with no avail. $site = preg_replace("/<!DOCTYPE(.|\s)*<div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.