extract shortcodes from string

i need a little help to with this issue:

I have a string wich contains shortcodes like [shortcode data="1" data2="2"]
How I can extract with regex? without wordpress system?

Read More

Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Where is this string located ?
    I know you wrote “without wordpress system” , but WordPress has a function get shortcode regex

    If you really want to avoid it for some reason, the following example might help you :

    // check the post for a short code 
    function check_shortcode( $shortcode = NULL ) {
    
        $post_to_check = get_post( get_the_ID() );
    
        // Until we search, set false 
        $found = false;
    
        //  no short - FALSE
        if ( ! $shortcode ) {
            return $found;
        }
    
        // check the post content for the short code 
        if ( stripos( $post_to_check->post_content, '[' . $shortcode) !== FALSE ) {
            // we have found the short code
            $found = TRUE;
        }
    
        // return our final results 
        return $found;
    }