question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlight regex issue when HTML is on a single line

See original GitHub issue

I want to highlight all words in an HTML that start with a specific string, “OfficeSuite” in my case, e.g. “OfficeSuite” and “OfficeSuiteabc” should be highlighted.

It is not working when I have the following HTML: <div>some text</div><div>OfficeSuite</div>

But it works when the HTML is formatted in multiple lines: <div>some text</div> <div>OfficeSuite</div>

I assume this is because when the HTML is on one line, after the tags are stripped what remains is “some textOfficeSuite” which violates the rule that the word should start with “OfficeSuite”.

Is there a way to make this work?

I’m using markjs v9.0.0

To Reproduce Example of working and not working version of the same code, the only difference being the HTML is/is not formatted on multiples lines. mark-js-test.zip

Desktop (please complete the following information):

  • Chrome

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
krohitdevcommented, Jun 1, 2021

Hi ✋ @Nevca , I have tested your shared zip file (test.html). I observe the regex expression and modified it. After modifying it observed that updated expression is more efficient and matches your requirement.

`// window.htmlViewer.highlightRegex(‘(?<![\p{L}])(officesuite)’);

window.htmlViewer.highlightRegex(‘(?<![\p{L}0-9])(officesuite)’);`

Please check

image

0reactions
stale[bot]commented, Aug 20, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript single-line comments interpreted as regex #1534
I am using highlight.js v9.11.0. It seems certain word combinations cause the double slash of single-line comments to be interpreted as an ...
Read more >
A one-line solution to highlighting search matches - bitsofcode
One way to do this is to save the html string with the highlights into a separate variable from the original text. Then...
Read more >
What is the regex to find a single line of text preceding a ...
I am trying to automatically highlight all questions onblur of a textarea. javascript · regex · Share.
Read more >
Highlight Text Within a String Using Angular and Regular ...
We're going to see how to highlight text within HTML using a query string and simple replace logic. The logic behind what we're...
Read more >
Regular expression syntax reference | IntelliJ IDEA ... - JetBrains
This section is a brief summary of regexp syntax that can be used for creating search and replace as well as issue navigation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found