#2691 Regex group always fails

ahhatem Thu 12 Apr 2018

Hi,

Sorry for a certainly silly question but regex group matching always fails.. What is wrong with this:

conString := "jdbc:oracle:thin:@(DESCRIPTION =  (LOAD_BALANCE = OFF)(ADDRESS = (PROTOCOL = TCP)(HOST = hostName)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = someService) ))"
deviceReg := Regex <|.*HOST\s?=\s?(\w+).*|>
device := deviceReg.matcher(conString).group(1);
echo ("device = $device");

I always get: sys::Err: No match found

SlimerDude Thu 12 Apr 2018

When I plug the values into the Fantex website the regex seems to work fine - group(1) returns hostname.

But I notice you're not calling RegexMatcher.find() before grabbing the group. Try this:

conString := "..."
deviceReg := "...".toRegex
matcher   := deviceReg.matcher(conString)

matcher.find()

device    := matcher.group(1)
echo ("device = $device");

ahhatem Thu 12 Apr 2018

Thanks a lot. That did it...

SlimerDude Thu 12 Apr 2018

The initial err msg of sys::Err: No match found when no match has been attempted is misleading though. Perhaps it should be updated?

ahhatem Thu 12 Apr 2018

Yes, indeed. Why not call find before attempting to return the group in case it wasn't called before?

Login or Signup to reply.