-3

Is there a feature in javascript such as deleting words starting with "<" and ending with ">"? For example I want to extract html codes from this object

      "description": "<mainText><stats><attention> 25</attention> Hareket Hızı</stats></mainText><br>",

1 Answers1

0

Sounds like a job for regex.

I think this could do it:

// BAD CODE
function useRegex(input) {
    let regex = /^<[a-zA-Z]+> <[a-zA-Z]+><[a-zA-Z]+>$/i;
    return regex.test(input);
}

EDIT: seems like my idiot self has messed this one up. Don't use regex, as commented by someone else.

I personally hate regex, so here are some tools to help you

Website to help you get started https://regexr.com/

And how to apply that in Javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

Regex code creator. It's like magic https://regex-generator.olafneumann.org/

Tarik
  • 60
  • 1
  • 9