Reputation: 1937
My string is :
str = {!Chirag patel>1|2|3|4|5}<br /><br />asdadasd<br /><br />{!Test>T|E|S|T}<br /><br />Chirag patel<br /><br />{!HELLO>H|E|L|L|O}
How i will get below result using a str.match in array:
0: Chirag patel>1|2|3|4|5
1: Test>T|E|S|T
2: HELLO>H|E|L|L|O
I already tried below code:
str.match(/^{![^}]+}+/g);
but it give me only one match , but i want all the match
I want to replce my find word using like as below.
if i find : Chirag patel>1|2|3|4|5
then i want a below code is replace in to the string.
<div><select class="template-field" data-field-name="chirag patel">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
</select></div>
Upvotes: 0
Views: 41
Reputation: 26161
You may do as follows;
var str = "{!Chirag patel>1|2|3|4|5}<br /><br />asdadasd<br /><br />{!Test>T|E|S|T}<br /><br />Chirag patel<br /><br />{!HELLO>H|E|L|L|O}",
matches = str.match(/[^\{!]+(?=\})/g);
console.log(matches);
Upvotes: 2
Reputation: 1690
First we need more infos, about what you have already tried, what do you really want, ect, even if i undertsand what's your main goal, explain more please!
And wich langage do you use? HTML, okay, i'am not stupid, but do you use nodejs, angular, simple javascript, jQuery??
Anyway, you should take a look at the javascript ".split" method, if you pass "<br />
" as the spliting argument you should get what you want.
Upvotes: 0