Jump to content

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


lostnucleus

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.