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

Quantifier follows nothing in regex; marked by ... 3

Status
Not open for further replies.

CristianLuca

Programmer
Oct 25, 2007
36
RO
I've tryed to escape the first "*" but it does not work either("\*/1 * * ....)

....
my $cronjobPattern = "*/1 * * * * /usr/bin/perl \$pathHome/test.pl 10";
...
if ($cronjob =~ m/$cronjobPattern/g) {
...
}
...


ERROR : Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE /1 * * * * /usr/bin/perl $pathHome/test.pl 10/ at monitor_crawlers.pl line 40.



Thank you in advance ,
Cristian
 
Try:
Code:
my $cronjobPattern  = "\\* 1 \\* \\* \\* \\* /user/bin/perl /$pathHome/test.pl 10";

The string is double-interpolated: Once when assigning to $cronjobPattern, and then again in the regex.

So each asterisk requires double escaping.

Also, I change the slash before $pathHome from a back slash to a forward slash.
 
You're trying to match a literal string. Therefore use quotemeta within your regex to automatically escape any special characters instead of having to manually escape those you happen to remember.

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$cronjobPattern[/blue]   = [red]"[/red][purple]*/1 * * * * /usr/bin/perl /[blue]$pathHome[/blue]/test.pl 10[/purple][red]"[/red][red];[/red]
[gray][i]#...[/i][/gray]
[olive][b]if[/b][/olive] [red]([/red][blue]$cronjob[/blue] =~ [red]m/[/red][purple][purple][b]\Q[/b][/purple][blue]$cronjobPattern[/blue][purple][b]\E[/b][/purple][/purple][red]/[/red][red]g[/red][red])[/red] [red]{[/red]
	[gray][i]#...[/i][/gray]
[red]}[/red]
[gray][i]#...[/i][/gray]

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top