Sundar Ban
Sundar Ban

Reputation: 619

How to write superscript for string in javascript

Hello friend I have a data in the object section_data.title.Well I am using different

    str= str.replace(/ft2/g,"ft<sup>2</sup>"); 
    str=str.replace(/m2/g,"m<sup>2</sup>"); 

for superscript

where str=section_data.title; str="Not less than 30 net ft2 (2.8 net m2) per patient in a hospital or nursing home, or not less than 15 net ft2 (1.4 net m2) per resident in a limited care facility, shall be provided within the aggregated area of corridors, patient rooms, treatment rooms, lounge or dining areas, and other similar areas on each side of the horizontal exit. On stories not housing bed or litterborne patients, not less than 6 net ft2 (0.56 net m2) per occupant shall be provided on each side of the horizontal exit for the total number of occupants in adjoining compartments."

How can i Write a single regular expression for both to work out? thanks

Upvotes: 0

Views: 2803

Answers (1)

Guffa
Guffa

Reputation: 700840

Make a regular expression that matches both units and captures the base unit, so that you can use that in the replacement string:

str = str.replace(/(ft|m)2/g,"$1<sup>2</sup>");

Upvotes: 2

Related Questions