case INsensitive regular expressions

S

sabinosa

Hi everyone,
I am working with a RegularExpressionValidator in Visual Studio.NET.
I would like to define a custom regular expression that ignores the
letter case and therefore is case INsensitive. I have seen that the
syntax might be something like "(?i)" or "/i". However, when I try to
use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)
the result is a javascript error. The error says: "Syntax error in
regular expression"
(^(CSV|ZIP|TXT)$/i does not work)

Any idea what I am doing wrong? Thanks in advance for your responses!
 
J

Jürgen Exner

sabinosa said:
I am working with a RegularExpressionValidator in Visual Studio.NET.

Interesting! I didn't know that Visual Studio.NET supports Perl. I guess
there is always something new to learn.
I would like to define a custom regular expression that ignores the
letter case and therefore is case INsensitive. I have seen that the
syntax might be something like "(?i)" or "/i".

Why don't you check the readily available documentation?

From "perldoc perlre":
Matching operations can have various modifiers. Modifiers that relate to
the interpretation of the regular expression inside are listed below.
Modifiers that alter the way a regular expression is used by Perl are
detailed in the section on "Regexp Quote-Like Operators" in the perlop
manpage and the section on "Gory details of parsing quoted constructs"
in the perlop manpage.

i Do case-insensitive pattern matching.
However, when I try to
use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)

This is not a regular expression. Well, it might be, but ...
the result is a javascript error.

Your system must be badly screwed up. Why would perl report a javascript
error?
The error says: "Syntax error in
regular expression"
(^(CSV|ZIP|TXT)$/i does not work)

At least the trailing /i is the correct syntax.
Please post a short, but selfcontained program that exposes the problem,
together with a description of what you expect the program to do versus what
behaviour you are observing. Then we may be able to determine if the problem
is with your code or your expectation.
Any idea what I am doing wrong?

For once: not posting any actual code. How are we supposed to reproduce and
analyse your problem if you don't tell us how.

jue
 
V

Vijai Kalyan

Hi everyone,
I am working with a RegularExpressionValidator in Visual Studio.NET.
I would like to define a custom regular expression that ignores the
letter case and therefore is case INsensitive. I have seen that the
syntax might be something like "(?i)" or "/i". However, when I try to
use that as part of my regular expression (ex. (?i)^(CSV|ZIP|TXT)$)
the result is a javascript error. The error says: "Syntax error in
regular expression"
(^(CSV|ZIP|TXT)$/i does not work)

Any idea what I am doing wrong? Thanks in advance for your responses!

(Javascript question in Javascript related newsgroup might get you more help.)

Simplest (and possibly the worst!) solution:

i. Convert your input into UPPERCASE. In c-talk:

int x=0;
static char s[INPUT_BUF_SIZE];
memset(s,'\x0',INPUT_BUF_SIZE);
strncpy(s,input,INPUT_BUF_SIZE];
for(; x != '\x0' && x < INPUT_BUF_SIZE ; toupper(s[x]), ++x);

ii. Check if 's' above matches.

iii. toupper is a macro, so this costs you time linear to size of your input.

BTW,

------------------------------
[>] RegExp Syntax

var myRegExp = /pattern/[switch]

In a Regular Expression /pattern/ is a Regular Expression and [switch]
(optional) indicates the mode in which the Regular Expression is to be used:

"i" - ignore case,
"g" - global search,
"gi" - global search + ignore case (case-insensitive).

After a Regular Expression is created, it is passed to a Method of a String
Object.
------------------------------

so why not try,

var input = /^(CSV|ZIP|TXT)$/

?

The answer to your question (finally) is:

google case insensitive pattern matching in javascript


:)


hth,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top