# Multi search with regex

**URL:** <https://pdfjs.community/t/multi-search-with-regex/3442>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [September 17, 2024, 2:28pm UTC](https://pdfjs.community/t/multi-search-with-regex/3442 "2024-09-17T14:28:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [September 17, 2024, 2:28pm UTC](https://pdfjs.community/t/multi-search-with-regex/3442/1 "2024-09-17T14:28:43Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
6.3.4  
**Detailed description of issue**  
we have been looking for a viewer with multi search capability along regex/wild characters. i went through the documentation but couldn’t be able to find it. is there any way to achieve this?

**Expected behaviour**  
If i provide multiple search terms those need to be highlighted in the viewer along with existing features

**Does your issue happen with every document, or just one?**  
NA

**Link to document**  
NA

**Code snippet**  
NA

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [September 17, 2024, 4:00pm UTC](https://pdfjs.community/t/multi-search-with-regex/3442/2 "2024-09-17T16:00:21Z")

</div>

Hi there,

You could use the textSearchInit API along with keeping previous results using something like this:

```javascript
const results = [];

const performSearch = (searchTerm) => {
  return new Promise(resolve => {
    const mode = Core.Search.Mode.PAGE_STOP | Core.Search.Mode.HIGHLIGHT | Core.Search.Mode.AMBIENT_STRING | Core.Search.Mode.REGEX;
    const searchOptions = {
      fullSearch: true,
      onResult: (result) => {
        results.push(result);
        documentViewer.displayAdditionalSearchResult(result);
      },
      onDocumentEnd: () => {
        resolve();
      }
    };
    documentViewer.textSearchInit(searchTerm, mode, searchOptions);

    documentViewer.displayAdditionalSearchResults(results);
  });
};

  await performSearch(searchTerm1);
  await performSearch(searchTerm2);
  await performSearch(searchTerm3);

```

This will keep highlight on multiple results:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/8/824abdf40084197202ec585ac474210c496dbf4c.png)

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [September 18, 2024, 5:59am UTC](https://pdfjs.community/t/multi-search-with-regex/3442/3 "2024-09-18T05:59:22Z")

</div>

Hi Kevin thanks for the quick reply .it’s perfectly working. is there a way to show all the search terms in the ui to the end user?.

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [September 18, 2024, 2:35pm UTC](https://pdfjs.community/t/multi-search-with-regex/3442/4 "2024-09-18T14:35:01Z")

</div>

Glad that worked for you,

There is no simple api to show the search terms, but you could grab the DOM input element in the search panel and manually fit them in during the search:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/d/d877c18d60292cd6840b5ee855965e8c56588418.png)

Best regards,  
Kevin Kim

---

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [September 19, 2024, 5:07am UTC](https://pdfjs.community/t/multi-search-with-regex/3442/5 "2024-09-19T05:07:01Z")

</div>

Thank you so much. will try it.

---

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [September 24, 2024, 6:26am UTC](https://pdfjs.community/t/multi-search-with-regex/3442/6 "2024-09-24T06:26:10Z")

</div>

Hi @kkim one more question like if we are doing search from the ui input then existing search results are disappearing. is there anyway to keep previous results as well with the ui search?

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [September 24, 2024, 3:29pm UTC](https://pdfjs.community/t/multi-search-with-regex/3442/7 "2024-09-24T15:29:20Z")

</div>

Hi there,

Unfortunately performing a search on the UI would mean cancelling and performing a new search. By design it will stop the current search and start a new search.
