import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?<author>(?:(?!$)[A-Za-z\\s&.,'’])+)\\((?<year>\\d{4})\\)\\.?\\s*(?<title>[^?.!]+?[.?!])\\s*(?:(?<retrieved>[Rr]etrieved.+)|(?:(?:(?<jurnal>(?:(?!^[A-Z])[^,])+?),\\s*(?<issue>\\d+)))|\\s*In(?<editors>[^\\(]+)\\(Eds\\.\\),(?<book>[^.()]+))?";
final String string = "Every day, millions of users interact with each other via graphical avatars in real\n"
+ "time in online games (Chan & Vorderer, 2006). All of them are using an avatar that\n\n"
+ "differs from their physical appearance. In fact, most of them are using avatars that\n"
+ "are attractive, powerful, youthful, and athletic. Although most research in CMC has\n"
+ "focused on the technical affordances of the medium (lack of social cues, social pre-\n\n"
+ "sence, anonymity, etc.), we argue that theoretical frameworks of self-representation\n"
+ "cannot be ignored because choosing who we are is a fundamental aspect of virtual\n"
+ "environments. More importantly, who we choose to be in turn shapes how we be-\n\n"
+ "have. Although avatars are usually construed as something of our own choosing—\n"
+ "a one-way process—the fact is that our avatars come to change how we behave.\n\n\n\n"
+ "Acknowledgments\n\n"
+ "The current work was partially supported by National Science Foundation (NSF)\n"
+ "Grant 0527377. The authors would like to thank Claire Carlson, Gerron Crochet, and\n\n"
+ "Kathryn Rickertsen for their assistance in conducting the experiment, as well as Jim\n"
+ "Blascovich for providing helpful feedback on an earlier draft of the paper.\n\n\n"
+ "Notes\n\n"
+ "1 In the analysis of Experiment 1, there was no significant interaction effect with the race\n\n"
+ " of the participant. In Experiment 2, participants do not see their own avatar, so this was\n"
+ " not an issue.\n"
+ "2 In both studies, the effect of subject gender was not significant, and including this factor\n"
+ " in the ANOVA did not change the reported significance of the results.\n\n\n"
+ "Human Communication Research 33 (2007) 271–290 ª 2007 International Communication As287iation\n"
+ "The Proteus Effect N. Yee & J. Bailenson\n\n"
+ "3 In the cases where this caused a mismatch between the perceived and actual height of the\n\n"
+ " participant’s avatar, real-time algorithms using trigonometry were used to correct the\n"
+ " eye-gaze angle between the participant and the confederate to preserve the possibility of\n"
+ " making eye contact.\n\n\n\n\n\n"
+ "References\n\n"
+ "Anonymous. (1998). To reveal or not to reveal: A theoretical model of anonymous\n"
+ " communication. Communication Theory, 8, 381–407.\n\n"
+ "Bailenson, J. (2006). Transformed social interaction in collaborative virtual environments.\n"
+ " In P. Messaris & L. Humphreys (Eds.), Digital media: Transformations in human\n"
+ " communication (pp. 255–264). New York: Peter Lang.\n\n"
+ "Bailenson, J., Beall, A., Blascovich, J., Loomis, J., & Turk, M. (2005). Transformed social\n"
+ " interaction, augmented gaze, and social influence in immersive virtual environments.\n\n"
+ "Linden Labs (2006). What is second life? Retrieved May 5, 2006, from lindenlab.com/ ProductFactSheet.pdf\n"
+ "Fearon, J. D., & Laitin, D. D. (2003). Ethnicity, Insurgency, and Civil War. American Political Science Review, 97(01), 75. doi: 10.1017/S0003055403000534\n"
+ "Jacobson, D. (1999). Impression formation in cyberspace: Online expectations and offline experiences in text-based virtual communities. Journal of Computer-Mediated Communication, 5. Retrieved April 26, 2007, from http://jcmc.indiana.edu/vol5/issue1/ jacobson.html\n\n"
+ "Chan, E., & Vorderer, P. (2006). Massively multiplayer online games. In P. Vorderer &\n"
+ " J. Bryant (Eds.), Playing computer games—Motives, responses, and consequences. Mahwah,\n\n"
+ " NJ: Lawrence Erlbaum.\n"
+ "Culnan, M. J., & Markus, M. L. (1987). Information technologies. In F. M. Jablin &\n"
+ " L. L. Putnam (Eds.), Handbook of organizational communication: An interdisciplinary\n\n"
+ " perspective (pp. 420–443). Thousand Oaks, CA: Sage Publications.\n"
+ "Dion, K., Berscheid, E., & Walster, E. (1972). What is beautiful is good. Journal of Personality and Social Psychology, 24, 285–290.\n\n"
+ "Flanagin, A. J., Tiyaamornwong, V., O’Connor, J., & Seibold, D. R. (2002).\n"
+ " Computer-mediated group work: The interaction of member sex and anonymity.\n\n"
+ " Communication Research, 29, 66–93.\n"
+ "Forsythe, R., Horowitz, J., Savin, N., & Sefton, M. (1994). Fairness in simple bargaining\n"
+ " experiments. Games and Economic Behavior, 6, 347–369.\n\n"
+ "Frank, M., & Gilovich, T. (1988). The dark side of self and social perception: Black uniforms\n"
+ " and aggression in professional sports. Journal of Personality and Social Psychology, 54,\n"
+ " 74–85.\n\n"
+ "Freedman, D. G. (1979). Human sociobiology. New York: Free Press.\n\n\n"
+ "288 Human Communication Research 33 (2007) 271–290 ª 2007 International Communication Association\n"
+ "N. Yee & J. Bailenson The Proteus Effect\n\n"
+ "Friend, R. M., & Vinson, M. (1974). Leaning over backward: Jurors responses to defendants’\n\n"
+ " attractiveness. Journal of Communication, 24, 124–129.\n"
+ " Human Communication Research, 31, 511–537.";
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