473,385 Members | 1,396 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,385 software developers and data experts.

Help needed with reg exp please

Could you please help me out with regular expressions. I'm trying to
write a perl script that proccesses some text, and i'm stuck at the
following:

need to remove from the text below all words starting and ending with
lower case letters. Words maybe followed by dot "." or not (most do),
and may contain a "-" character:
eg:

---> Apis calc. Carb-v. cham. dendr-pol. halia-lac. hep. lac-leo. lyc.
Med. nat-m. nit-ac. nux-v. OPIUM plat. polys. PULS. rauw. sal-fr.
Sanguis-s sil. sulph. Tarent. tung-met. VERAT. viol-o vio-zinc.
zinc-c.

should yield:

---> Apis Carb-v. Med. OPIUM PULS. Sanguis-s Tarent. VERAT.
ie words starting with a capital letter must remain untouched.
I've tried various combinations of reg exp before posting here, but
could not find the right one.
I'd really appreciate your help.
Jul 19 '05 #1
4 3329
Aristotle wrote:
Could you please help me out with regular expressions.
<snip>
I've tried various combinations of reg exp before posting here,


Show us!

And consult e.g. "perldoc perlrequick", if you haven't done so already.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Jul 19 '05 #2
Aristotle wrote:
I've tried various combinations of reg exp before posting here, Gunnar Hjalmarsson wrote:Show us!


I managed to get the desired effect by using the following code; it
gets the job done, but it looks ugly:

{
$parts[1] =~ s/ ([a-z]+[a-z]) / /g;
$parts[1] =~ s/ ([a-z]+[a-z])./ /g;
$parts[1] =~ s/ ([a-z]+[a-z]) / /g;
$parts[1] =~ s/ ([a-z]+[a-z])./ /g;
$parts[1] =~ s/ ([a-z]) / /g;
$parts[1] =~ s/ ([a-z])./ /g;
}

However that was after trying MANY, MANY exps, eg:

$parts[1] =~ s/([a-z]+[a-z]\.)//g;
$parts[1] =~ s/([a-z]*[a-z]\.)//g;
$parts[1] =~ s/([a-z][a-z]+\-[a-z]\.)//g;
$parts[1] =~ s/([a-z][a-z]+\-.[a-z])//g;
$parts[1] =~ s/([a-z][a-z]+[a-z])//g;

I'm no expert, i did what i could...
If you think you can help, please do so without questioning me.
Jul 19 '05 #3
Aristotle wrote:
Gunnar Hjalmarsson wrote:
Aristotle wrote:
need to remove from the text below all words starting and
ending with lower case letters. Words maybe followed by dot "."
or not (most do), and may contain a "-" character:

eg:

---> Apis calc. Carb-v. cham. dendr-pol. halia-lac. hep.
lac-leo. lyc. Med. nat-m. nit-ac. nux-v. OPIUM plat. polys.
PULS. rauw. sal-fr. Sanguis-s sil. sulph. Tarent. tung-met.
VERAT. viol-o vio-zinc. zinc-c.

should yield:

---> Apis Carb-v. Med. OPIUM PULS. Sanguis-s Tarent. VERAT.

ie words starting with a capital letter must remain untouched.

I've tried various combinations of reg exp before posting here,


Show us!


I managed to get the desired effect by using the following code; it
gets the job done, but it looks ugly:

{
$parts[1] =~ s/ ([a-z]+[a-z]) / /g;
$parts[1] =~ s/ ([a-z]+[a-z])./ /g;
$parts[1] =~ s/ ([a-z]+[a-z]) / /g;
$parts[1] =~ s/ ([a-z]+[a-z])./ /g;
$parts[1] =~ s/ ([a-z]) / /g;
$parts[1] =~ s/ ([a-z])./ /g;
}

However that was after trying MANY, MANY exps, eg:

$parts[1] =~ s/([a-z]+[a-z]\.)//g;
$parts[1] =~ s/([a-z]*[a-z]\.)//g;
$parts[1] =~ s/([a-z][a-z]+\-[a-z]\.)//g;
$parts[1] =~ s/([a-z][a-z]+\-.[a-z])//g;
$parts[1] =~ s/([a-z][a-z]+[a-z])//g;

I'm no expert, i did what i could...
If you think you can help, please do so without questioning me.


There are all too many lazy people who have no real interest in
learning Perl, and who believe that groups like this one are just free
help desks. I asked you to prove that you are not one of those by
posting code. You need to live with that, whatever you call it, or
else few people are willing to assist.

Anyway, this is one way to do it with one substitution:

s/\s+[a-z][-\w]*[a-z]\.?//g;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Jul 19 '05 #4
Gunnar Hjalmarsson wrote:
Anyway, this is one way to do it with one substitution:

s/\s+[a-z][-\w]*[a-z]\.?//g;


Should better be:

s/\s*[a-z][-\w]*[a-z]\.?//g;
--------^

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Hubbard | last post by:
I want to implement the same type of activeX restrictions in my browser application that the new SP2 for XP places in Internet Explorer. I have found 2 web pages dealing with this functionality...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
1
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
14
namcintosh
by: namcintosh | last post by:
Hello, everyone. Well, let me cut to the chase and explain my problem. I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight...
0
by: Christopher | last post by:
Urgent Help Needed: The EPVH-1.1 Visual Hull Library. Dear All, I am a student doing research in computer vision. The EPVH-1.1 Visual Hull Library will really help a lot in my research. I...
5
by: justbovo | last post by:
Hello, My name is Justin. I am working on a part of a Find Memory module for a program. Here's how it works.. I enter '13' at the main menu which branches out to my Find Memory module. I ask...
8
by: 08butoryr | last post by:
Hey guys I could really use your help with some very basic java programming. I know you programming fundis out there will find this child's play but I'm struggling with it a bit because I'm...
13
by: DDragon | last post by:
ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other...
4
by: princessfi | last post by:
Hi, I'm new to visual basic. I have a problem. i connected the database to the form and i added the code below to prompt if there is any blank textbox. When nothing is entered into the textbox and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.