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="[email protected]" />
    <input type="hidden" name="cntnt01input_email_again" value="[email protected]" />
    <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>
5
  • 3
    (related) Best Methods to parse HTML Commented May 10, 2011 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 Commented May 10, 2011 at 11:59
  • I'm sure it will help :) and it's much more reliable than using Regex. Commented May 10, 2011 at 12:35
  • What do you want to replace? The complete row where "message" is found? Commented May 10, 2011 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 &amp;quot;Email&amp;quot; is already in use by another registered user" .. oh not stated below is that $foo is that whole html block above. Commented May 11, 2011 at 22:37

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

5 Comments

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 :)
Why do you want to replace? Can't you just put the match into a new string?
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 &amp;quot;Email&amp;quot; is already in use by another registered user" "
Oooo! Smarty... and I've just noticed the single-line-mode modifier.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.