# Search Config Question: Dealing with (lack of) spaces in OCR text

**URL:** <https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799>\
**Category:** General Discussion\
**Created:** [August 22, 2023, 4:42pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799 "2023-08-22T16:42:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebellempire](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ebellempire/32/1552_2.png) [@ebellempire](https://pdfjs.community/u/ebellempire)\
**Post date:** [August 22, 2023, 4:42pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799/1 "2023-08-22T16:42:55Z")

</div>

I’m using [version 8.7.4](https://www.npmjs.com/package/@pdftron/pdfjs-express), installed manually on an existing website. The PDFs on this site are historical documents with OCR’d text that generally does not have spaces between words. So searching for a phrase basically never works. See example below.

## Single word search

Note the OCR text preview

 ![single word search](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/4/44141e5d20575f7fe9d5ecf9baec10b6ef5a9b29.jpeg)

Is there a configuration that can help with this issue (e.g. by turning spaces into an optional wildcard)? I know that the core PDFjs viewer, as implemented in Firefox, does not have this limitation, so maybe there’s a well-known way to deal with this.

Below is my code, which is pretty close to default.

```javascript
  const pdf = document.querySelector("[data-pdf]");
  if(pdf){
    WebViewer({
      path: 'xxx',
      licenseKey: "xxx",
      initialDoc: pdf.dataset.pdf,
      disabledElements: [
        'toolsHeader',
        'ribbonsDropdown',
        'toggleNotesButton',
        'printButton',
        'ribbons',
        'contextMenuPopup'
      ]
    }, document.getElementById('viewer')).then(instance => {
      const docViewer = instance.docViewer;
      const annotManager = instance.annotManager;
      instance.UI.setTheme('dark');
    });
  }

```

Thanks!

NOTE: Continuing with some additional screenshots below (new users can only include one file upload per post).

---

<div class="post-metadata">

**Author:** ![ebellempire](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ebellempire/32/1552_2.png) [@ebellempire](https://pdfjs.community/u/ebellempire)\
**Post date:** [August 22, 2023, 4:43pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799/2 "2023-08-22T16:43:55Z")

</div>

## Searching a phrase w/o spaces

Note the OCR text preview

 ![omitting the space](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/4/48c3300aaa73103f5e33b9261bcb705a22e67d62.jpeg)

---

<div class="post-metadata">

**Author:** ![ebellempire](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ebellempire/32/1552_2.png) [@ebellempire](https://pdfjs.community/u/ebellempire)\
**Post date:** [August 22, 2023, 4:44pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799/3 "2023-08-22T16:44:58Z")

</div>

## Searching a phrase _with_ spaces

 ![including the space to search for a phrase](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/0/02a19443d8e811140d94d9f9597992d9bef11157.jpeg)

---

<div class="post-metadata">

**Author:** ![ebellempire](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/ebellempire/32/1552_2.png) [@ebellempire](https://pdfjs.community/u/ebellempire)\
**Post date:** [August 22, 2023, 4:46pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799/4 "2023-08-22T16:46:02Z")

</div>

## Same document search in Firefox

Works as expected in PDFjs, as implemented in Firefox

 ![firefox search](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/4/44d8ab35309546efa4f71fa4c5a6b52a9397d6ca.jpeg)

---

<div class="post-metadata">

**Author:** ![darian.chen](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@darian.chen](https://pdfjs.community/u/darian.chen)\
**Post date:** [August 23, 2023, 6:47pm UTC](https://pdfjs.community/t/search-config-question-dealing-with-lack-of-spaces-in-ocr-text/2799/5 "2023-08-23T18:47:01Z")

</div>

Hi there,

You would have to implement your own regex search.

Here is a link to a useful guide on searching: [Basic searching | Documentation](https://pdfjs.express/documentation/search/basic-search.8#searching-a-document-one-by-one)

Thank you.

Best Regards,  
Darian Chen
