Monday, 15 July 2013

Java get matches group of Regex -



Java get matches group of Regex -

given next java look codes:

boolean match = row.matches("('.*')?,('.*')?");

if match true, means regex matches whole 'row'. content of 2 groups? each 1 ('.*')?

to access groups need utilize matcher: pattern.compile(regex).matcher(row).

then can phone call find() or matches() on matcher execute matcher , if homecoming true can access groups via group(1) , group(2).

string row = "'what','ever'"; matcher matcher = pattern.compile("('.*')?,('.*')?").matcher( row ); if( matcher.matches() ) { string group1 = matcher.group( 1 ); string group2 = matcher.group( 2 ); }

java regex

No comments:

Post a Comment