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.

specialChars not identifying correct regular expression

See original GitHub issue

I have the following regular expression:

/\[\[\s?date\(\'([0-9a-zA-Z\s\:\-\+]*)\'(\s?,\s?\'([a-zA-Z \-\:]*)\')?\)\s?\]\]/g

Which matches the following string:

I went for a walk on '[[date('last week', 'Y-m-d')]]' and '[[ date('today') ]]'

Results can be seen here:

https://regex101.com/r/XC8gQT/2

However, when I try to use the regular expression with specialChars, the text is not replaced as I would expect.

The code I’ve used is:

window.onload = function() {
        editor = CodeMirror.fromTextArea(document.getElementById("query"), {
            lineNumbers: true,
            mode: "text/x-mysql",
            matchBrackets: true,
            specialChars: /\[\[\s?date\(\'([0-9a-zA-Z\s\:\-\+]*)\'(\s?,\s?\'([a-zA-Z \-\:]*)\')?\)\s?\]\]/g,
            specialCharPlaceholder: function(ch) {
                var node = document.createElement("span");
                node.innerHTML = 'it-works';
                node.className = "special";
                node.title = 'It works!';
                return node;
            }
        });
    };

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marijnhcommented, Oct 1, 2016

Nope, sorry, I am not being paid enough to act as a help desk.

0reactions
amochohancommented, Oct 1, 2016

Could you provide a small code sample to get me started?

Read more comments on GitHub >

github_iconTop Results From Across the Web

specialChars not identifying correct regular expression #4271
The code I have has placeholders, which i'd like to apply some CSS to or add a class. Such a placeholder would be...
Read more >
Regex pattern including all special characters - Stack Overflow
Regex just starts at the ascii index and checks if a character of the string is in ... However you can think of...
Read more >
Special characters in regexes and how to escape them - Threesl
Information on special characters in regular expressions and how you can escape them to include them in your match.
Read more >
Regular Expression (Regex) Tutorial
Regular Expression, or regex or regexp in short, is extremely and amazingly powerful in searching and manipulating text strings, particularly in processing ...
Read more >
Regex Tutorial - Literal Characters and Special Characters
The most basic regular expression consists of a single literal character, such as a. It matches the first occurrence of that character in...
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