help with string replace - for doing selective replace

P

Prasad S

Hello

I wish to replace all the characters in a string except those which
are inside '<' & '>' characters. And there could be multiple
occurences of < & > within the string.

e.g. string = "this is an example of <how> many words could be hidden
<under> these characters"

now, from this string all the characters should be searched & replaced
by a certain logic except <how> & <under>

I am accepting the string from a textarea form field and there can be
no or multiple occurences of words within < >

Any help will be highly appreciated.
 
E

Evertjan.

Prasad S wrote on 20 aug 2004 in comp.lang.javascript:
I wish to replace all the characters in a string except those which
are inside '<' & '>' characters. And there could be multiple
occurences of < & > within the string.

e.g. string = "this is an example of <how> many words could be hidden
<under> these characters"

s = "an example of <how> words <under> these characters"

s = s.replace(/[^<]*(<[^>]*>)[^<]*/g,'$1')
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 20 Aug 2004 06:12:36, seen in
Prasad S said:
I wish to replace all the characters in a string except those which
are inside '<' & '>' characters. And there could be multiple
occurences of < & > within the string.

Can the string be of the form " x < y < z > a > ? ", If so, some record
of depth-of-quote is called for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top