freelanceprogrammers.org Forum Index » Perl
Reg: Clarification in Pattern Matching
Joined: 13 Aug 2005
Posts: 12
Reg: Clarification in Pattern Matching
Hai Folks,
I have a very small clarification in pattern matching, though it
seems to be so silly I`m not able to find a solution, please help me in this
regard. I want to match a string into which a particular string should not be
present, i.e. You can assume any string which contains lots of words out of
which i want to match a pattern in which words starting with "b" should be
matched and ending should be "y" and between "b" and "y" no "a" should be
present. This can be done using m/b(?!a)y/ig, but it is not working right for
me. In detail, i want to search for html tags i.e. <b> and i should match start
<b> and end </b> inside of which no <b> tag should be present. Please help me in
this regard.
Thanks in Advance,
Regards
Krish
Krish
Senior Software Engineer (Perl)
---------------------------------
Yahoo! Mail
Use Photomail to share photos without annoying attachments.
[Non-text portions of this message have been removed]
Joined: 28 Feb 2006
Posts: 1
Reg: Clarification in Pattern Matching
--- In Perl_Official@yahoogroups.com, Krishna Prasad <skpkrish@...> wrote:
>I want to match a string into which a particular string should not be
>present, i.e. You can assume any string which contains lots of words
>out of which i want to match a pattern in which words starting with
"b" >should be matched and ending should be "y" and between "b" and
"y" no >"a" should be present. This can be done using m/b(?!a)y/ig,
but it is >not working right for me.
[ysawant@ipmon01 ~]$ cat match_trial.pl
#!/usr/bin/perl
use strict;
while (<>) {
print if (m/b[^a]*y/i);
}
[ysawant@ipmon01 ~]$ cat somefile
this is a sample file
with a b in it
b for bold
an html tag
b is also for bank
and bay
bay of bengal?
bblahy
by
bigy
[ysawant@ipmon01 ~]$ ./match_trial.pl somefile
by
bigy
[ysawant@ipmon01 ~]$
Cheers
Yogesh
Joined: 21 May 2004
Posts: 44
Reg: Clarification in Pattern Matching
>>>>> "Yogesh" == Yogesh Sawant <yoga_sawant@...> writes:
Yogesh> print if (m/b[^a]*y/i);
That strategy works fine if "a" is a single character, but fails miserably
when you have a multichar string there. The solution I posted will work for
either.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Joined: 13 Aug 2005
Posts: 12
Reg: Clarification in Pattern Matching
Hai Yogesh,
Thanks for your initiative to reply me. But probably you have
misunderstood my requirement and Mr. Merlyn has very well understood that and it
helped me a lot. Anyway thanks a lot Yogesh.
Regards
Krish
merlyn@... wrote: >>>>> "Yogesh" == Yogesh Sawant
<yoga_sawant@...> writes:
Yogesh> print if (m/b[^a]*y/i);
That strategy works fine if "a" is a single character, but fails miserably
when you have a multichar string there. The solution I posted will work for
either.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
SPONSORED LINKS
C programming language
Computer programming languages Java
programming language
The c programming language C programming
language Concept of programming language
---------------------------------
YAHOO! GROUPS LINKS
Visit your group "Perl_Official" on the web.
To unsubscribe from this group, send an email to:
Perl_Official-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Krish
Senior Software Engineer (Perl)
---------------------------------
Yahoo! Mail
Bring photos to life! New PhotoMail makes sharing a breeze.
[Non-text portions of this message have been removed]
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







