Asked  7 Months ago    Answers:  5   Viewed   26 times

How can I make the following regex ignore case sensitivity? It should match all the correct characters but ignore whether they are lower or uppercase.




Assuming you want the whole regex to ignore case, you should look for the i flag. Nearly all regex engines support it:


string.match("G[a-b].*", "i")

Check the documentation for your language/platform/tool to find how the matching modes are specified.

If you want only part of the regex to be case insensitive (as my original answer presumed), then you have two options:

  1. Use the (?i) and [optionally] (?-i) mode modifiers:

  2. Put all the variations (i.e. lowercase and uppercase) in the regex - useful if mode modifiers are not supported:


One last note: if you're dealing with Unicode characters besides ASCII, check whether or not your regex engine properly supports them.

Tuesday, June 1, 2021
answered 7 Months ago

Continue calling re.exec(s) in a loop to obtain all the matches:

var re = /s*([^[:]+):"([^"]+)"/g;
var s = '[description:"aoeu" uuid:"123sth"]';
var m;

do {
    m = re.exec(s);
    if (m) {
        console.log(m[1], m[2]);
} while (m);

Try it with this JSFiddle:

Tuesday, June 1, 2021
answered 7 Months ago

If you merely want to check whether a regular expression is valid or not, simply try to compile it with whichever programming language or regular expression library you're working with.

Parsing regular expressions is far from trivial. As the author of RegexBuddy, I have been around that block a few times. If you really want to do it, use a regex to tokenize the input, and leave the parsing logic to procedural code. That is, your regex would match one regex token (^, $, w, (, ), etc.) at a time, and your procedural code would check if they're in the right order.

Thursday, July 1, 2021
answered 6 Months ago

Flags go at the end.


i is for case-Insensitive (or ignore-case)

Saturday, July 3, 2021
answered 6 Months ago

The short/simple answer: case-sensitivity varies from standard to standard, and the particular implementations you were using have case-sensitive identifiers. But this information is probably not very helpful in isolation. So what went "wrong"?

Given that you mention #langs, it's clear you were using Racket. Racket is a descendant of Scheme, but it does not conform to any existing Scheme standard. However, Racket is extensible—it can support lots of languages, even user-defined ones—so different iterations of Scheme are supported by Racket.

Which Schemes are case-sensitive?

There are three relevant versions of the Scheme standard in existence at the time of this writing, R5RS, R6RS, and R7RS.

  • R5RS is always case-insensitive.
  • R6RS is always case-sensitive.
  • R7RS is case-sensitive by default, but the #!fold-case directive or the include-ci form can disable case-sensitivity.

As you can see, this issue really isn't clear-cut: it hasn't remained consistent over the past three standards. In fact, given that R7RS and R6RS are both case-sensitive by default, it might be more accurate to say that Scheme is case-sensitive now. However, while R5RS has been outdated for a long time, it continues to live on as "The Scheme" used in many books, interpreters and compilers, and other materials, hence the possible conclusion that "Scheme is case-insensitive."

Which Scheme were you using?

None of them. Perhaps confusingly, even #lang scheme isn't an implementation of any Scheme standard. In truth, #lang scheme is a deprecated language that has been completely supplanted by #lang racket (the former existed before PLT Scheme was renamed to Racket, much in part to reduce the confusion about its "Scheme" not being an actual Scheme implementation).

So, you may ask, how can you get actual Scheme inside of Racket? Well, Racket does provide implementations of the various Scheme standards. Both #lang r5rs and #lang r6rs are built-in implementations of the relevant Scheme standards. An R7RS implementation is available as #lang r7rs through the r7rs package.

All of Racket's languages can interoperate, so your language of choice is up to you, though the RnRS languages tend to go unused in the Racket community (#lang racket is much more useful for writing programs than any of the Scheme implementations), but they can be useful if you want to write programs that run on different Scheme implementations.

Sunday, November 14, 2021
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :