LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2005, 07:56 PM   #1
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Rep: Reputation: 30
Perl Pattern Matching Question


I'm fairly new to perl and I'm having a slight pattern matching issue.

The problem piece of code looks something like this:

until ($variable =~ /word/i) {
do things}

My problem is that as long as "word" is present the until function ignores whatever comes before word. I'd like to fix this.

I had the same problem with characters which came after "word", and I fixed that by doing something like this:

until (($variable =~ /word/i) and ($variable !~ /word./) and ($variable !~ /word./)){
do things}

This works fine for characters after "word", but I can't seem to get the check to work for characters that appear before "word".

Any help is appreciated.
 
Old 08-27-2005, 12:53 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
what exactly are you trying to match?

if you want to match strings that say "word" exactly, then you can use /^word$/ (this use is unnecessary as "lc($variable) eq 'word' " will do). ^ asserts the beginning of the line, and $ asserts the end.

if you want to match strings where "word" is surrounded by whitespace or boundary of string, you can use /\bword\b/ (\b asserts word boundary)

you can also construct more complicated assertions
 
Old 08-27-2005, 10:26 AM   #3
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Original Poster
Rep: Reputation: 30
Thank you very much for your help. /^word$/ was sufficient. I was trying to match different things, as I was having the problem with all my programs. Most irritating were a few programs I wrote for my girlfriend. One of which would check for our names, and she kept inserting obnoxiously things before my name and laughing. It had to be stopped. Thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
list files NOT matching a pattern smart_sagittari Linux - Newbie 9 05-20-2005 05:32 AM
perl regex matching exodist Programming 2 11-15-2004 10:50 PM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 09:53 AM
Doubt in Pattern matching and vi editor.. suriyamohan Linux - General 2 08-19-2003 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration