Hi. I am trying to match a string:
"RemoveAcc $k: $v"

There are an arbitrary number of spaces between RemoveAcc and the two variables...Preferably I would like to store these to variables using $1 and $2 after the string is parsed, but I do not want to save the RemoveAcc part (that is just a flag). Here is my code:

elsif(my $rawRequest = checkForRequest("removea")){
      if($rawRequest ne "DONT"){
      my ($valid,$request) = CheckRequest($rawRequest);
     #Only if there is a valid request that says delete do we delete the contact (using the email that we scrape from the request
      if ($valid and ($request =~ (RemoveAcc .*\s)(\w+):(\w+)/)){  
.......

...My program complains about this regex, and I am not familiar enough with them to troubleshoot myself. I don't understand shashes. If I don't need parenthesis around the whole $request = please let me know also...Thank you!

Not sure if you intended to allow a space between the colon and $v or not. Assuming not, the following should work.

#!/usr/bin/perl
#Regex.pl
use 5.006;
use strict;
use warnings;

#Assign some values to variables and build request string
my $k = 'kryptonite';
my $v = 'valium';
my $valid = 1;
my $request = "RemoveAcc $k:$v";# <----No space allowed between : and $v, right?
print "request is $request\n";
if ($valid and ($request =~ m/RemoveAcc\s*(\w+):(\w+)/)){
	my $first = $1;
	my $second = $2;
	print "First value is $first\nSecond value is $second\n";
} else {
	print "Not valid or doesn't match\n";
}
commented: thanks that did it. (you're right, the space wasn't supposed to be there, but i put it there so it didn't make a smiley :$" +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.