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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple regex 3

Status
Not open for further replies.

netman4u

Technical User
Mar 16, 2005
176
US
Hello All,

Been some time since I posted. A little rusty here.

I Need a regex that will match any string that ends with an "_D". I have this:

/code

foreach $entry (@combin) {
next if ($entry =~ /^*.?_D$/);
do something else;
}

Will this work?

Thanks,

Nick

If at first you don't succeed, don't try skydiving.
 
It need not be so involved

Your conditions are:

[red]1.[/red] _D
[red]2.[/red] end of line

so...

/_D$/

... should do the trick

Kind Regards
Duncan
 
Yeah, your regex should work, but you don't really need to match anything at the beginning of the string. It can be simplified like this:
Code:
next if ($entry =~ /_D$/);
If there is the possibility of whitespace at the end of the line, you might want to use:
Code:
next if ($entry =~ /_D\s*$/);
 
Thanks for the replies.

I must be missing something here.

Code:
#!/bin/perl
my @combin = ("anything_D,something_H");
foreach (@combin) {
	next if /_D$/;
	print "$_\n";
}

Output:

Code:
anything_D,sonmething_H

If at first you don't succeed, don't try skydiving.
 
Doh!!!

I knew it. Something stupid.

Thanks

[blush]

If at first you don't succeed, don't try skydiving.
 
Cummon folks! Enough back patting! LOL



If at first you don't succeed, don't try skydiving.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top