0

How to extract html tags from a file using javascript regex.

I try with this regex /<.*>.*<\/.*>/s but it not give the expected result.

here is my source file

My Source File

import { Component, Input, OnInit, ViewEncapsulation, Output, 
EventEmitter } from '@angular/core';


@Component({
  selector: 'mgmt-ui-input',
  templateUrl: './ui-input.component.html',
  styleUrls: ['./ui-input.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class UiInputComponent implements OnInit {
  /**
   *  @example
   *  <mgmt-ui-input
   *    [showIconX]="true"
   *    [showIconV]="true"
   *    (close)="onClose($event)"
   *  >
   *    <input type="text">
   *  </mgmt-ui-input>
   *
   *
   *
   * show icon x
   * @type {boolean}
   */
  @Input() showIconX = true;
  @Input() showIconV = true;
  @Output() close = new EventEmitter<void>();

  constructor() {
  }

  ngOnInit() {
  }

}

here is the expected result from the regex

Expected Result

<mgmt-ui-input
  [showIconX]="true"
  [showIconV]="true"
  (close)="onClose($event)"
>
  <input type="text">
</mgmt-ui-input>
1

1 Answer 1

2

You can upgrade your regex by using un-greedy version of * (check this). Also, your regex doesn't work with self closing tags. Check this one:

<.*?>.*?<\/.*?>|<.*?\/>

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.