Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SilentPanda

Moderator emeritus
Original poster
Oct 8, 2002
9,997
33
The Bamboo Forest
So this is the Apple/Tech discussion forum so I hope this is okay here... it's more tech than Apple.

Anyhow... I'm trying to get a regular expression to work. The expression is:
Code:
^[^ES]

This should match anything whose first character does not begin with E or S. I know the only data coming in will be E, S, M, and R1. In Perl this works just fine. But when I use the ".matches" method of String in Java it doesn't match R1!

Granted I could do it with a simple if statement but I don't see why it won't work. Anybody? 😕
 
That expression would only match one character, which is why R1 wouldn't work.

You could try something like

^[^ES]\w*

or if R1 is your only two character string, use
^[^ES]|R1


Of course, I have no way to test this at the moment, so let me know if it works.
 
I'll give it a shot. I'm installing the 1.4.2 Java SDK right now in case there were some changes between 1.4.1 and 1.4.2 to what I'm using (doubtful but I've been meaning to upgrade anyhow).

The odd thing is that my regex worked just fine in Perl. But I'll try your's as soon as the install is done.

Thanks!
 
Code:
^[^ES]\w*

This one worked like a champ. I also tried
Code:
^[^ES]*?

which worked too. Yeah! Still weird that it worked in Perl but not in Java... oh well... different engines I guess... thanks for the help!

😀
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.