import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\s*(\\w*)=\\s?\\d";
final String string = "#!/bin/bash\n\n"
+ "flavor=${1:-dzen2}\n\n"
+ "function gmail() {\n"
+ "while true\n"
+ "do\n"
+ " inbox_count=$(wget -q -O- --auth-no-challenge --user=something@gmail.com --password=something 'https://mail.goog$\n"
+ " echo \"Gg:$inbox_count\"\n"
+ " sleep 60\n"
+ "done\n"
+ "}\n\n"
+ "function weather() {\n"
+ "while true\n"
+ "do\n"
+ " weather_stat=$($HOME/.config/i3/./weather.sh)\n"
+ " echo \"F$weather_stat\"\n"
+ " sleep 900\n"
+ "done\n"
+ "}\n\n"
+ "function time_date() {\n"
+ "while true\n"
+ "do\n"
+ " klocka=$(date +'%A den %d %B v%V %H:%M')\n"
+ " echo \"S$klocka\"\n"
+ " sleep 10\n"
+ "done < <(echo)\n"
+ "}\n\n"
+ "bspc control --put-status\n"
+ "xtitle -sf \"T%s\" > \"$PANEL_FIFO\" &\n"
+ "weather > \"$PANEL_FIFO\" &\n"
+ "gmail > \"$PANEL_FIFO\" &\n"
+ "time_date > \"$PANEL_FIFO\" &\n"
+ "case \"$flavor\" in\n"
+ "bar)\n"
+ " cat \"$PANEL_FIFO\" | .config/bspwm/panel_bar | bar\n"
+ ";;\n"
+ "dzen2)\n"
+ " . .config/bspwm/panel_colors\n"
+ " PANEL_HEIGHT=14\n"
+ " FONT_FAMILY='Dejavu Sans'\n"
+ " FONT_SIZE=9\n"
+ " cat \"$PANEL_FIFO\" | .config/bspwm/panel_dzen2 -f \"$FONT_FAMILY\" -s \"$FONT_SIZE\" | \\\n"
+ " dzen2 -h $PANEL_HEIGHT -dock -ta l -title-name panel -fn \"${FONT_FAMILY}:pixelsize=${FONT_SIZE}\" \\\n"
+ " -fg \"$COLOR_FOREGROUND\" -bg \"$COLOR_BACKGROUND\"\n"
+ ";;\n"
+ "esac";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html