Regex Help

L

lmcosorio

Hi Everyone,

I've been learning Perl for about 6 months. This is my first post to
the group as it's also the first time i couldn't find an answer on this
group or elsewhere.

Here's my problem. I want to match a line from a file with the
following conditions:

1 - It starts with aaa?
2 - Has random characthers following the "?"
3 - ends with s=196

1 & 2 are variables.

Below is a sample script a wrote that shows (almost) what i need. I use
the \Q modifier because of the "?" on the 1st variable.
I can't seem to figure out how to match randoms characters between
$var1 and $var2. To make things harder (at least for me) the randoms
characters can contain special regex characters.

use strict;
use warnings;
my $match1='aaa?';
my $match2='s=196';
my $var='aaa?s=196';

if ($var =~ /\Q$match1$match2/)
{
print "It matched...";
}


where i have:
if ($var =~ /\Q$match1$match2/)

i need to have

if ($var =~ /\Q$match1[match any random characters]$match2/)

Any help apreciated.
I hope my question is understandable and please forgive my english.

Regards,

Luis
 
D

Dr.Ruud

(e-mail address removed) schreef:
if ($var =~ /\Q$match1[match any random characters]$match2/)


I think you are looking for:

$var =~ /\A\Q${match1}\E.*\Q${match2}\E\z/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top