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.

Highlighting causes "Invalid regular expression" when text contains brackets or points

See original GitHub issue

Bootstraptable version(s) affected

1.19.0

Description

If the highlighter is used on columns that contain parentheses ( “[”, “]”, “(” or “)”), then an exception occurs. This seems to happen only with isHTML, because there a replace is done with the TextContent. This TextContent contains the brackets and therefore this is part of the RegEx. The TextContent would have to escape the brackets and perhaps also points before.

In code it’s line 1602: defValue = value.replace(new RegExp('(>\\s*)(${textContent})(\\s*)', 'gm'), '$1${textReplaced}$3')

Excpetion: bootstrap-table.js:5609 Uncaught SyntaxError: Invalid regular expression: /(>\s*)(Executed DbCommand (0ms) [Parameters=[@__id_0=‘2’], CommandType=‘Text’, CommandTimeout=‘30’] SELECT TOP(1) [k].[KundenId], [k].[ContactPersonName], [k].[ContactPersonPhone], [k].[CurrentUserCount], […)(\s*)/: Unterminated character class at new RegExp (<anonymous>) at bootstrap-table.js:5609 at Array.forEach (<anonymous>) at _class.initRow (bootstrap-table.js:5504) at _class.initBody (bootstrap-table.js:5693) at _class.load (bootstrap-table.js:6498) at Object.success (bootstrap-table.js:5968) at y (bundle.min.js?v=hNhfPDGCO8NKbO5bs-qED6Kq9wSl5PxyUBi_3SCDFgs:2) at Object.fireWith [as resolveWith] (bundle.min.js?v=hNhfPDGCO8NKbO5bs-qED6Kq9wSl5PxyUBi_3SCDFgs:2) at b (bundle.min.js?v=hNhfPDGCO8NKbO5bs-qED6Kq9wSl5PxyUBi_3SCDFgs:2) (anonym) @ bootstrap-table.js:5609 initRow @ bootstrap-table.js:5504 initBody @ bootstrap-table.js:5693 load @ bootstrap-table.js:6498 success @ bootstrap-table.js:5968

Example(s)

No response

Possible Solutions

No response

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
UtechtDustincommented, Nov 10, 2021

I guess there are some more chars which should be escaped. The following should do the job.

value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

Example: https://regex101.com/r/b1d1p4/1

1reaction
twelve-cgncommented, Nov 10, 2021

I will give it a try today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vs code Invalid regular expression Lone Qualifier brackets
Certain characters have special meaning in regex and if you wish to use them literally then you must escape them, a quantifier bracket...
Read more >
Regular Expression Support in ReSharper 9 | The .NET Tools ...
Matching Braces for Regular Expressions in ReSharper 9. ReSharper is capable of highlighting invalid characters and escape character ...
Read more >
Searching - Notepad++ User Manual
Selecting Search Mode of Regular expression will cause the Match whole word only option to become unchecked and disabled (greyed out). A possible...
Read more >
Regular Expressions: The Complete Tutorial - GitHub Pages
A regular expression (regex or regexp for short) is a special text string for describing a ... At this point, the entire regex...
Read more >
Regular expression - Wikipedia
A regular expression is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms...
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