Saturday, November 14, 2015

Java regex - matching multiple groups in a string:

If you want to be able to extract each captured group as a separate Matcher group, then make sure you put greedines sysmbol INSIDE the bracket. For example, this will be fetched correctly as a whole expression: Pattern.compile("(\r|\n\|.)+?=(\r|\n|.)+?") Matcher.group(0) will return whole fetched text. However, Matcher.group(1) and Matcher.group(2) will return something like empty strings! In order to properly obtain group 1 and 2, you should use this: Pattern.compile("(\r|\n\|.+?)=(\r|\n|.+?)") Now you will have it all : group 0 (all), group 1 and group 2!

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...