Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:59:59+00:00 2026-05-16T08:59:59+00:00

I think this question is repeated, but searching wasn’t helpful for me. my $pattern

  • 0

I think this question is repeated, but searching wasn’t helpful for me.

my $pattern = "javascript:window.open\('([^']+)'\);";
$mech->content =~ m/($pattern)/;
print $1;

I want to have an external $pattern in the regular expression. How can I do this? The current one returns:

Use of uninitialized value $1 in print at main.pm line 20.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:00:00+00:00Added an answer on May 16, 2026 at 9:00 am

    $1 was empty, so the match did not succeed. I’ll make up a constant string in my example of which I know that it will match the pattern.

    Declare your regular expression with qr, not as a simple string. Also, you’re capturing twice, once in $pattern for the open call’s parentheses, once in the m operator for the whole thing, therefore you get two results. Instead of $1, $2 etc. I prefer to assign the results to an array.

    my $pattern = qr"javascript:window.open\('([^']+)'\);";
    my $content = "javascript:window.open('something');";
    my @results = $content =~ m/($pattern)/;
    # expression return array
    # (
    #     q{javascript:window.open('something');'},
    #     'something'
    # )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this question is probably fairly simple, but I've been searching around and
I am using PrimeFaces p:messages but I think this question applies equally to h:messages
I mostly develop using C#, but I think this question might be suitable for
I'm coming largely from a c++ background, but I think this question applies to
Sorry it seems like a repeated question, BUT I think I don't qualify to
First thing I know this is repeated question but I don't have problem in
I think this question may end up being a bit subjective so I'm marking
I think this question is really about my understanding of Garbage collection and variable
I don't think this question has been asked before. I'm a bit confused on
I got this question in a programming test. Do you think this question is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.