How can I rectify a string that begins and ends with a backtick, while ensuring that the contents of the evaluated expression also contain backticks?

Joined
Oct 24, 2013
Messages
47
Reaction score
0
JavaScript:
const abcd = `[@parent.[#(?object=activity::criteria=typeid=76273 AND tbl_1770949.valuestr="1"::orderby=tbl_1770943.valuestr ASC){"userid":"$txtUserid$","organisations":"$rdOrganisations$","oversightGroupRole":"$cmbOversightRole$","oversightGroupMemberName":"$txtOversightPrefix$ $txtOversightFirstName$ $txtOversightSurname$","oversightGroupType":"$cmbOversightGroupType$"},#]@]`;

//Please note the statment
[@parent.[#(?object=activity::criteria=typeid=76273 AND tbl_1770949.valuestr="1"::eek:rderby=tbl_1770943.valuestr ASC){"userid":"$txtUserid$","organisations":"$rdOrganisations$","oversightGroupRole":"$cmbOversightRole$","oversightGroupMemberName":"$txtOversightPrefix$ $txtOversightFirstName$ $txtOversightSurname$","oversightGroupType":"$cmbOversightGroupType$"},#]@]
evaluates the string in the format below-e.g

JavaScript:
[{
    "userid": "88664753",
    "organisations": "Liverpool Heart and Chest Hospital NHS Foundation Trust*NIHR CRN Northwest Coast*University of Liverpool*",
    "oversightGroupRole": "Member",
    "oversightGroupMemberName": "Mr abcd",
    "oversightGroupType": "Steering Committee"
}, {
    "userid": "",
    "organisations": "University of Liverpool*",
    "oversightGroupRole": "Member",
    "oversightGroupMemberName": "Professor ccc",
    "oversightGroupType": "Steering Committee"
}, ]

My statement fails if any one the properties(userid,organisations etc) values contains backtik.
How can I fix that. How can I rectify an evaluated expression string that begins and ends with a backtick, while ensuring that the contents of the evaluated expression also contain backticks?
 
Joined
Jul 4, 2023
Messages
400
Reaction score
44
If you want to retain backticks in the text and just ensure they don't interfere with the enclosing backticks used for string delimiting, you would escape them. Escaping a character means prepending it with another character, usually a backslash (\), to signify that it should be treated as a literal character rather than having its usual special meaning.
JavaScript:
let newText = text.replace(/`/g,"\\`");
 

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

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top