Regex replace problem


Joined
Jan 6, 2022
Messages
2
Reaction score
0
In a script I have a variable that is something like this…
JavaScript:
var = “our >A< found >B< and lost >R<“
The upper case letters in between the tags may be different from time to time but will always be a single, upper case character in the range A to Z.
I want to replace each letter in between the characters “>” and “<“ with a question mark character yieding this..

Code:
var = “our >?< found >?< and lost >?<“

I have scoured JS regex tutorials but my tries don’t work. Help will be greatly appreciated.
 
Last edited:
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
This seems to work.

JavaScript:
const str = 'our >A< found >B< and lost >R<';
const regex = />[A-Z]</g;

console.log(str.replaceAll(regex, '>?<'));
 
Ad

Advertisements


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

Top