Restricting JavaScript regular expressions to single line

18 views
Skip to first unread message

Neil

unread,
Jul 26, 2026, 10:03:10 PM (10 days ago) Jul 26
to scintilla-interest
The hypertext (HTML), xml, and cpp lexers recognize regular expression literals in JavaScript. These start and end with '/' so may appear like this

"x 100".match(/\d+/)

'/' is also used for division so there is some code to choose between the '/' being an operator or the start of a regular expression literal. The implementation is not always accurate. It examines previous text for various characters that imply the likelihood of one choice. The regular expression literal terminates after another '/' but it also terminates at the end of the line.

This implies that a regular expression literal can not continue onto subsequent lines. I have not found a definitive statement that this is the case but searching for related terms on the web did not produce contradicting evidence.

Therefore, it may improve the lexers to only transition to regex literal style when the initiating '/' is followed by at least one more '/' on the same line.

Neil

Neil Hodgson

unread,
Jul 29, 2026, 6:45:50 PM (7 days ago) Jul 29
to scintilla...@googlegroups.com
Committed the change to JavaScript regular expression literal
detection for both the cpp and XML/HTML lexers.

The committed changes can be examined either in the repository

git clone https://github.com/ScintillaOrg/lexilla

or from

https://www.scintilla.org/scite.zip Source
https://www.scintilla.org/wscite.zip Windows executable (64-bit)

Neil
Reply all
Reply to author
Forward
0 new messages