-6

I would like to create a regular expression to remove the line-height of a style, can be the following standards:

<p align="justify" style="margin-bottom: 0cm; font-weight: normal; line-height: 100%; text-decoration: none">

Or that:

<p align="justify" style="margin-bottom: 0cm; font-weight: normal; line-height: 100%">

the property can end with " or ; and may have any value.

  • 2
    Try a proper html parser because http://stackoverflow.com/a/1732454/995891 (or if you dare `htmlString.replaceAll("line-height:\\s*\\d+\\%;?", "")` – zapl Jun 16 '16 at 06:34
  • I try to create something like: `line-height:[^\"]+\"|line-height:[^;]+;` Look that: [sample](http://regexr.com/3dksf) but select a text-decoration. – Romulo Fagundes Jun 16 '16 at 06:36
  • [*Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.* - Jamie Zawinski](http://regex.info/blog/2006-09-15/247) –  Sep 06 '16 at 15:51
  • Exact duplicate of [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) –  Sep 06 '16 at 15:51

2 Answers2

0
const removeLineHeightTag = (text: string) => {
  const regex = /(line-height: ((\d).)*(;)*)/g;
  try {
    return `${text.replace(regex, '')}`;
  } catch (e) {
    return text;
  }
};

let yourText = '...' // change to your text
yourText = removeLineHeightTag(yourText)
Aroldo Goulart
  • 134
  • 1
  • 11
-1

Use this regex: (line-height:[\d\s]+%;?). To replace it, do the following.

yourString.replaceAll("(line-height:[\\d\\s]+%;?)", "");  
Abdul Fatir
  • 6,159
  • 5
  • 31
  • 58