javascript - find/get specific strings between strings -
suppose, have string this
"lorem ipsum dolor sit amet, [b]consectetur adipisici elit[/b], sed eiusmod tempor [i]incidunt ut labore[/i] et [size =12]dolore [/size=12] magna aliqua"
i like lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore
magna aliqua". not question.
question: how strings between [b]...[\b]
, [i] ..[/i]
or string between [size=12].. [/size=12]
in textarea, when append div? text between [b][/b] should become bold, between [i][/i]
should become italic , text between [size][/size]
should font size...
you need 2 separated pattern:
to between [b]
, [\b]
:
\[b\](.*?)\[\/b\]
var str = "lorem ipsum dolor sit amet, [b]consectetur adipisici elit[/b], sed eiusmod tempor [i]incidunt ut labore[/i] et dolore magna aliqua"; var result = /\[b\](.*?)\[\/b\]/.exec(str); document.write(result[1]);
to between [i]
, [/i]
:
\[i\](.*?)\[\/i\]
var str = "lorem ipsum dolor sit amet, [b]consectetur adipisici elit[/b], sed eiusmod tempor [i]incidunt ut labore[/i] et dolore magna aliqua"; var result = /\[i\](.*?)\[\/i\]/.exec(str); document.write(result[1]);
also if need replace content, try this:
var str = "lorem ipsum dolor sit amet, [b]consectetur adipisici elit[/b], sed eiusmod tempor [i]incidunt ut labore[/i] et dolore magna aliqua"; var result = str.replace(/\[b\]|\[\/b\]/g,'**').replace(/\[i\]|\[\/i\]/g,'*'); document.write(result);
Comments
Post a Comment