mercredi 29 novembre 2017

RegExp function with long text

I have a book with footnotes which I want to display.
I put the footnotes in their place inside curly brackets.

In order to retrieve the comments and display them in a different window, I wrote the following class in Angular 2:

export class BookreaderComponent implements OnInit {

async comments() {
    var regexp = new RegExp('\{(\s*?.*?)*?\}');
    var array= await regexp.exec(this.book);
    console.log(array);
  }

  constructor(public appServices: AppServices, private http: Http, private route: ActivatedRoute) { }
  book: string;
  Name: string;
  json: string;
  ngOnInit() {
    this.route.params.subscribe(params => {
      this.Name = params['name'];
      this.http.get("./assets/" + params['url'])
        .map(ref => {
          return ref;
        }).subscribe(async ref => {
          this.book = ref.text();
          await this.comments();
        });
    });

  }

The class calls the comments function, which calls a regex function on a large amount of text, that contains a lot of curly-bracketed text. The problem is that the regex function takes a very long time to load (I waited and waited, and it didn't load), and meanwhile the whole page is stuck.

Is there a way to speed this up, or maybe break this up into smaller chunks? Or maybe I should try a different way to display these footnotes?




Aucun commentaire:

Enregistrer un commentaire