0

Hello I need to pull out the value of the input that has the name ending in "message" and replace the whole thing with the match. It needs to be a replace. any ideas what the regex is for this?

Thank you for the help.. Cheers -Jeremy

I have tried alot and this is the last one

patteren /.*?(message" value="(.*?)").*?/is

replacement $2

wanting

The value specified for "Email" is already in use by another registered user

in

    <input type="hidden" name="cntnt01message" value="The value specified for &amp;quot;Email&amp;quot; is already in use by another registered user" />

for this content

    <form id="cntnt01moduleform_1" method="post" action="http://www..com/account/registration.html" class="cms_form">
    <div class="hidden">
    <input type="hidden" name="mact" value="SelfRegistration,cntnt01,default,0" />
    <input type="hidden" name="cntnt01returnid" value="60" />
    <input type="hidden" name="cntnt01assign" value="CONT" />
    <input type="hidden" name="cntnt01returnid" value="60" />
    <input type="hidden" name="cntnt01input_username" value="s" />

    <input type="hidden" name="cntnt01input_Salon" value="s" />
    <input type="hidden" name="cntnt01input_Hairstylist" value="s" />
    <input type="hidden" name="cntnt01input_email" value="s@cableone.net" />
    <input type="hidden" name="cntnt01input_email_again" value="s@cableone.net" />
    <input type="hidden" name="cntnt01input_Firstname" value="s" />
    <input type="hidden" name="cntnt01input_Lastname" value="Bass" />
    <input type="hidden" name="cntnt01input_phone" value="208-s-s" />
    <input type="hidden" name="cntnt01input_Street" value="s21st ave" />
    <input type="hidden" name="cntnt01input_city" value="s" />
    <input type="hidden" name="cntnt01input_state" value="Idaho" />
    <input type="hidden" name="cntnt01input_zip" value="s" />
    <input type="hidden" name="cntnt01input_Description" value="" />
    <input type="hidden" name="cntnt01input_services" value="Color,Perm/Relaxer,Sisterlocks®,Braiding" />
    <input type="hidden" name="cntnt01orig_url" value="http://www..com/account/registration.html?mact=SelfRegistration,cntnt01,default,0&amp;amp;cntnt01returnid=60&amp;amp;cntnt01group=Platinum&amp;amp;cntnt01pkg=4" />
    <input type="hidden" name="cntnt01group_id" value="4" />
    <input type="hidden" name="cntnt01pkg" value="4" />
    <input type="hidden" name="cntnt01submit
    " value="" />

    <input type="hidden" name="cntnt01error" value="1" />
    <input type="hidden" name="cntnt01message" value="The value specified for &amp;quot;Email&amp;quot; is already in use by another registered user" />
    </div>
Lee Kowalkowski
  • 11,591
  • 3
  • 40
  • 46
Quantum
  • 1,456
  • 3
  • 26
  • 54
  • 3
    *(related)* [Best Methods to parse HTML](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662) – Gordon May 10 '11 at 11:55
  • not sure parseing html is going to help here.. it has to be preg_replace ... I need the pattern is the thing .. tk – Quantum May 10 '11 at 11:59
  • I'm sure it *will* help :) and it's much more reliable than using Regex. – Gordon May 10 '11 at 12:35
  • What do you want to replace? The complete row where "message" is found? – stema May 10 '11 at 13:41
  • what the deal is that I am working in smarty so I need to match the value of the input who's name ends in "message" and use the callback to replace it all. the smarty is {$foo|regex_replace:'/patteren/':'replace ie: $1'} so at the end $foo is "The value specified for &quot;Email&quot; is already in use by another registered user" .. oh not stated below is that $foo is that whole html block above. – Quantum May 11 '11 at 22:37

1 Answers1

0

You're looking for .? (0 or 1 of any character except a new line). I think you should look for [^"]+ i.e.: /message" value="([^"]+)"/is and replace with $1 (not sure why the other brackets are there unless that's for something else).

Lee Kowalkowski
  • 11,591
  • 3
  • 40
  • 46
  • nope that didn't work either.. the other groups where to match the outside so when I replace with the call back the whole mass is replaced.. of that is the intent :) – Quantum May 10 '11 at 12:07
  • Why do you want to replace? Can't you just put the match into a new string? – Lee Kowalkowski May 10 '11 at 12:31
  • what the deal is that I am working in smarty so I need to match the value of the input who's name ends in "message" and use the callback to replace it all. the smarty is {$foo|regex_replace:'/patteren/':'replace ie: $1'} so at the end $foo is "The value specified for &quot;Email&quot; is already in use by another registered user" " – Quantum May 11 '11 at 22:36
  • Oooo! Smarty... and I've just noticed the single-line-mode modifier. – Lee Kowalkowski May 12 '11 at 07:21
  • So I see that this means you want to replace *everything* with the message. In which case the non-greedy `.*?` at the beginning and end will match nothing, because they don't have to. You can force them to by putting `^` at the start and `$` at the end, or by just using greedy expressions, e.g: `/.*(message" value="(.*?)").*/is` or `/^.*?(message" value="(.*?)").*?$/is`, or even `/^.*(message" value="(.*?)").*$/is` - That's the only problem I can see anyway. – Lee Kowalkowski May 12 '11 at 07:54