2
$str1='<option value="AAA">AAA</option><option value="BBB">BBB</option><option value="CCC">CCC</option>';

$str2='<option value="CCC">CCC</option><option value="DDD">DDD</option>';

I would like the expected result as following. If some part of $str2 which is duplicated with part of $str1, then removing the duplicated part of $str2.

Expected result:

$expectedStr = '<option value="DDD">DDD</option>';

Can anyone help me?

1 Answer 1

2
var str1='<option value="AAA">AAA</option><option value="BBB">BBB</option><option value="CCC">CCC</option>',
    str2='<option value="CCC">CCC</option><option value="DDD">DDD</option>',

    result = str2.replace(/<option .+?<\/option>/g, function(m) {
        return (str1.indexOf(m) > -1)? "" : m;
    });

console.log(result); //returns <option value="DDD">DDD</option>

(here I'm supposing you want to check for "atomic" substring <option>...</option>)

Example fiddle: http://jsfiddle.net/jAyAE/

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

Comments

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.