Jump to content

How to find " or ' in <input type="text" name="UserName" value="james" >


Recommended Posts

For exaple in

<input type="text" name="UserName" value="james" >

I wat to take out name and vlaue values, for this is used

'/<input type="[^r"]+"[^>]+name="([^"]+)"[^>]+value="([^"]*)"[^>]+>/i'

which works good for double quotes

 

But what if its single quotes insted of double ...

<input type='text' name='UserName' value='james' >

 

How can i write a single regex pattern which works on both types of quotes ??

 

Link to comment
https://forums.phpfreaks.com/topic/145747-how-to-find-or-in/
Share on other sites

I wat to take out name and vlaue values

 

$str = '<input type="text" name="UserName" value="james" >';
$str = preg_replace('#(<input.+?name=[\'"])[^\'"]+([\'"].+?value=[\'"])[^\'"]+([\'"][^>]+>)#i', '$1$2$3', $str);

 

Output (via right click view source):

<input type="text" name="" value="" >

 

I could have encased the first set of each quotes into captures like so: ([\'"]) then [^\'"]+, and finally use back referencing to use the same exact quote that was captured using \\x format. The reason I avoided this is simply to reduce captures... in the end, the above still works.

Link to comment
https://forums.phpfreaks.com/topic/145747-how-to-find-or-in/#findComment-765270
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.