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 7593521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:11:26+00:00 2026-05-30T21:11:26+00:00

I am building an admin UI where a user can manage a list PCRE

  • 0

I am building an admin UI where a user can manage a list PCRE strings which get passed to PHP’s preg_match at other points in my application.

Before storing the user’s input for later use by preg_match, I’d first like to validate that the user’s input is a valid PCRE expression, otherwise later on passing it to preg_match throws an error.

What’s the best way to validate a given string to see if it’s a valid PCRE in PHP?

  • 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-30T21:11:27+00:00Added an answer on May 30, 2026 at 9:11 pm

    Your best bet will be to just pass the string to preg_match, and catch any errors that happen.

    try{
        preg_match($in_regex, $string, $results);
        //Use $results
    } catch (Exception $e) {
        echo "Sorry, bad regex (/" . $in_regex . "/)";
    }
    

    [Edit]
    Since that won’t work, you could try:

    function bad_regex($errno, $errstr, $errfile, $errline){
        echo "Sorry, bad regex.";
    }
    set_error_handler("bad_regex");
    preg_match($in_regex, $string, $results);
    restore_error_handler();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building out an admin area for an ecommerce site where the user can
I am building a local intranet web application which uses the current user's AD
I am building a dynamic form in that the user can keep adding entries
In the system I am building user CAN NOT register them selves. The users
I am building an inventory management application with four different user types: admin, employee,
I am building a simple website that needs 3 user levels (member, mod, admin)
I am building a simple admin area for my site and I want the
In the admin section of a website i am building i would like to
What frameworks are targeted specifically at building so-called CRUD Admin UIs (basically, a set
building a site using PHP and MySQL that needs to store a lot of

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.