Vikas Nimse
Vikas Nimse

Reputation: 9

Match string which is half inside tag and half ouside

I want to match string with value "vikas" which is half in some tag(any tag dont use span only) and half outside of it.

e.g:

<span class="can-map"><span id="1" class="can-map">vikas</span></span> 
<span id="2" class="can-map">vi<span>kas</span></span>

by using this regex: /vikas/gi

I am getting value inside id=1 but not from id=2. Kindly help.

regexr link

Upvotes: 0

Views: 46

Answers (1)

Vlad Brezitskiy
Vlad Brezitskiy

Reputation: 34

function getVikas() { 
		const reg =  /vikas/gi;
    
    var one = document.getElementById('1');
    var two = document.getElementById('2');
    
   	console.log(reg.test(two.innerText)); // true
    
}

getVikas();
<span class="can-map"><span id="1" class="can-map">vikas</span></span> 
<span id="2" class="can-map">vi<span>kas</span></span>

Try something like this

Upvotes: 1

Related Questions