Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern match - find exact string in db line

Status
Not open for further replies.

ibjdt

Programmer
Nov 25, 2002
63
i am reading a flat text file to an array and then looking at each line for a string. I want to perform an operation if i find the exact string

Code:
$string = abc;
if ($line =~ /$string/) { do soemthing }

however, this will find abcd and zabc.
i only want to allow

::abc::
::abc|
|abc|
|abc::

thanks in advance.

 
maybe
/\:{1,2}|\|{1,2}abc\:{1,2}|\|{1,2}/

??


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
cleaner
/[\|\:]{1,2}abc[\|\:]{1,2}/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
of course.. if you don't care if you match once or twice on those :s |s
then
/[|:]abc[|:]/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Perl:
/(::)|\|abc(::)|\|/
perhaps?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
>$string = abc;
[tt]$string='(:):|\|)abc:):|\|))';[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top