Groups | Blog | Home
all groups > asp.net webcontrols > october 2004 >

asp.net webcontrols : case INsensitive regular expressions


maurof78 NO[at]SPAM aol.com
10/21/2004 10:05:27 AM
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)

Tad McClellan
10/21/2004 1:40:14 PM

[ Followups set ]


[quoted text, click to view]


Posting a question that is not related to Perl into the Perl newsgroup.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
wana
10/21/2004 5:00:30 PM
[quoted text, click to view]

maybe /^(CSV|ZIP|TXT)$/i will work.

Try this out:

#! /usr/bin/perl

print "usage: $0 filename\n" if not $test = @ARGV[0];
$match = ($test =~ /^(CSV|ZIP|TXT)$/i);
$match = $match ? "matched":"did not match";
$test = $test ? print "$test $match\n" : exit 1;
Abigail
10/21/2004 10:52:27 PM
sabinosa (maurof78@aol.com) wrote on MMMMLXIX September MCMXCIII in
<URL:news:e2d435fa.0410210905.14d25ea9@posting.google.com>:
:) 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!


You are using the wrong language. Perl regular expressions should
be used in Perl, not in javascript.



Abigail
--
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
vijai.kalyan NO[at]SPAM gmail.com
10/22/2004 1:47:42 AM
[quoted text, click to view]

(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)$/[i]

?

The answer to your question (finally) is:

google case insensitive pattern matching in javascript


:)


hth,
------
Jürgen Exner
10/22/2004 6:36:03 AM
[quoted text, click to view]

Interesting! I didn't know that Visual Studio.NET supports Perl. I guess
there is always something new to learn.

[quoted text, click to view]

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.

[quoted text, click to view]

This is not a regular expression. Well, it might be, but ...

[quoted text, click to view]

Your system must be badly screwed up. Why would perl report a javascript
error?

[quoted text, click to view]

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.

[quoted text, click to view]

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

AddThis Social Bookmark Button