Home: Perl Programming Help: Regular Expressions:
First in Perl expression - CreateTask('', '', 'qwe123_')

New User

May 6, 2011, 2:46 AM

Views: 7608
First in Perl expression - CreateTask('', '', 'qwe123_')

need create regular expression for such string
CreateTask('qwe123_', 'qwe123_', "qwe123_")

the qoutes can be ' or "
between all parts can be any whitespace, tabs and even returns.

I start trying with it - CreateTask('\w*',m/(\t|\s)/* but its not even compiled(



May 6, 2011, 10:23 AM

Views: 7603
Re: [Yola] First in Perl expression - CreateTask('', '', 'qwe123_')

Why not start with something even more basic like the following:

my $str = qq{ asdf  CreateTask('qwe123_', 'qwe123_', "qwe123_") asdfqwe}; 

if ($str =~ m/(CreateTask\(.*?\))/s) {
print $1;
} else {
warn "Func not found\n";

Note the use of the 's' modifier so that teh any character '.' will match returns. .*? is for non-greedy matching, so it will stop at the first ')'.

The only place where this will fail is if there are parenthesis within one of your string parameters. It would be possible to create a regex for that as well, but wanted to start with something simpler.

- Miller