473,608 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

match leading '*' in r.e... how?


I'm probably going to feel really stupid when I see the answer, but I'm now
stuck nevertheless... I need to match a leading literal '*', and Perl isn't
getting the idea. Reading from standard input, typing "const" into the program
below yields "just const" as expected, but typing "*const" ALSO results in it
just saying "just const", rather than "*const".

This is a simplification of a much more complex r.e. where I need to detect an
asterisk immediately preceding "const", and it isn't working either.

How am I being brain-dead?
-leor

while (<>)
{
if (/const/)
{
print "just const\n\n";
}
elsif (/\*const/)
{
print "*const\n\n ";
}
else
{
print "None.\n";
}
}

Jul 19 '05 #1
1 1466
Leor Zolman wrote:
I'm probably going to feel really stupid when I see the answer, but I'm now
stuck nevertheless... I need to match a leading literal '*', and Perl isn't
getting the idea. Reading from standard input, typing "const" into the program
below yields "just const" as expected, but typing "*const" ALSO results in it
just saying "just const", rather than "*const".

This is a simplification of a much more complex r.e. where I need to detect an
asterisk immediately preceding "const", and it isn't working either.

How am I being brain-dead?
-leor

while (<>)
{
if (/const/)
{
print "just const\n\n";
Nope, /const/ matches *const, constant, fooconstbar etc.

Always print the thingy when debugging... Not a silly message which
assumes your program works (which it doesn't).
}
elsif (/\*const/)
{
print "*const\n\n ";
}
else
{
print "None.\n";
}
}


To fix it: match the most specific one first. Also read how one can
create a "switch" in perl. It will quite likely make your code more
readable.
--
Kind regards, virtual home: http://johnbokma.com/ ICQ: 218175426
web site hints: http://johnbokma.com/websitedesign/
John I count my toes ~ one to ten ~ I meditate ~ and feel the Zen

Jul 19 '05 #2

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

Similar topics

20
5761
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT" >>>c = extract(a,b) >>>print c "abcdefghijklmnop"
19
2148
by: Tom Deco | last post by:
Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. My (probably to naive) approach is: p = re.compile(r'\b#include\b) I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use a backslash as escape character before the #
4
2103
by: hooterbite | last post by:
string: www.google.com "\\swww\\S*" returns " www.google.com' string: http://www.google.com "\\dwww\\d\\S*" matches, seems like it doesn't mind the http:// before the www. I want to match the string www.google.com, not http://www.google.com, and I don't want the space that the first regular expression includes...
8
10278
by: sherifffruitfly | last post by:
Hi, I've been searching as best I can for this - coming up with little. I have a file that is full of lines fitting this pattern: (?<year>\d{4}),(?<amount>\d{6,7}) I'm likely to get a bunch of hits with this - I'm only interested in the *last* one. Is there a way to build the concept "last" into the
7
13341
by: Petepinca | last post by:
I have 2 Access tables. One has a field with a 4 character product id. Example data: "3210". The other table has the same product id's for matching records BUT has leading characters: "RD3210", etc. I want to match records in an Access query that will match the fields based on the last 4 characters, which fortunately, are unique in both tables. I can edit in SQL View if necessary. Thanks for any help.
5
3470
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
2
1715
by: Jon Slaughter | last post by:
Can I use any reg exp(mainly for mod rewrite) where I can match any character but a fixed list? I need to match a string that does not contain any /'s but I don't want to have to use a character search string. (I don't see any need to have to hardcode it) that is, ..
6
7748
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for each file that he has us process. He wants this in a Comma Delimited Format.
4
2123
natalie99
by: natalie99 | last post by:
Hi All This may be a very basic question, please bare with me I am learning! I have two sets of data, one is the baseline of a Billing Inventory, the other is a seperate data set from the Live Inventory. The field I am trying to match is the ID field. There is no primary key in the Baseline inventory, ID can be duplicated, however, the other fields in the record will determine if it is, or is not, a duplicate entry or two legitimate...
0
8059
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8000
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8470
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1328
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.