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!
preg_replace("/\\{(\w)\\}/
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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-down load-link}
{meta_wpcf-thirdparty-feat ured-tool}
{meta_wpcf-thirdparty-yout ube-video- url}
{meta_wpcf-thirdparty-webs ite-url}
{meta__thumbnail_id}
The ones that start with meta are the ones that seem to fail with the current regex.
{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-down
{meta_wpcf-thirdparty-feat
{meta_wpcf-thirdparty-yout
{meta_wpcf-thirdparty-webs
{meta__thumbnail_id}
The ones that start with meta are the ones that seem to fail with the current regex.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.