Link to home
Start Free TrialLog in
Avatar of interclubs
interclubs

asked on

Regular Expression Help

I'm using the following regex to replace text in between curly brackets {}:
preg_replace("/\\{(\w)\\}/e", '$mappedFields[\1]', $template);

But I need to allow underscores and hyphens _-. How would I change it to allow for multiple hypens and underscores, like {__some-key--here}

Thanks!
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please post a sample of the test data you're using.  Where do you need to allow the underscores and hyphens?  In the pattern?  Or in the input strings?  Or in the output?  If we can see the test data and expected results, it will be easy to get you a good answer very quickly.  Thanks, ~Ray
Avatar of interclubs
interclubs

ASKER

Here is a sample of the data I am trying to match:

    {to_ping}
    {pinged}
    {post_modified}
    {post_modified_gmt}
    {post_content_filtered}
    {post_parent}
    {guid}
    {menu_order}
    {post_type}
    {post_mime_type}
    {comment_count}
    {filter}
    {post_thumbnail}
    {meta__edit_last}
    {meta__edit_lock}
    {meta_downloaded}
    {meta_wpcf-downloadlink}
    {meta_wpcf-thirdparty-download-link}
    {meta_wpcf-thirdparty-featured-tool}
    {meta_wpcf-thirdparty-youtube-video-url}
    {meta_wpcf-thirdparty-website-url}
    {meta__thumbnail_id}

The ones that start with meta are the ones that seem to fail with the current regex.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial