We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Regex Help - Any Regex Pros out there?

Development and Programming

vinci's avatar
vinci
85 posts
16 years ago
vinci's avatar vinci

I am trying to develop an extension to add a field into the publish entry page. I would like this to be added directly after the url_title field. Using the show_full_control_panel_end hook, I would like to perform a preg_match_all to find:

<div class="itemWrapper">
<div class="itemTitle"><label for="url_title">URL Title</label></div>
<input dir="ltr" style="width: 100%;" name="url_title" id="url_title" value="woodscrews" size="20" maxlength="75" class="input" type="text">
</div>

and add some html to the end of it.

the regex I currently have, as a starter, is:

$look_for = "/<div class='itemWrapper'[^>]*>[\s]*<div class='itemTitle'[^>]*>(.*)<\/div>(.*)<\/div>/";

Im no good at regex - I could do this very easily with jQuery, but would like to stick with a non-js solution.

Any help appreciated.

       
Stephen Lewis's avatar
Stephen Lewis
466 posts
16 years ago
Stephen Lewis's avatar Stephen Lewis

Hi vinci,

Is this a custom field type you’re creating? If so, I can heartily recommend Brandon Kelly’s FieldFrame extension, which does all the Regex heavy lifting for you.

That said, if you’re looking to insert something inside the itemWrapper div, after the url_title field, the following should be headed in the right direction. Please be aware that I haven’t had a chance to try this, so it may not be bang on the money yet, or particularly efficient for that matter.

Caveats dispensed with, here you go:

$old_content = '<div class="itemWrapper"> etc. etc. </div>';
$replacement_content = "${1}${2}${3}This will be inserted inside the itemWrapper div, after the url_title field.${5}${6}";
$new_content = preg_replace('/^(.*)(name="url_title")(.*?)>(.*?)(<\/div>)(.*)$/i', $replacement_content, $old_content);

Hope that helps.

Stephen

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.