import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:^|(?<=\\|))[^|]*\\bpresident\\b[^|]*(?=\\||$)";
final String string = "{{Redirect|Harvard}} {{pp-move-indef}} {{Use mdy dates|date=August \n"
+ "2014}} {{pp-semi-blp|small=yes}}{{Infobox university |name = Harvard \n"
+ "University |image_name = Harvard Wreath Logo 1.svg |image_size = |caption \n"
+ "= [[Seal (emblem)|Seal]] of Harvard University |latin_name = Universitas \n"
+ "Harvardiana |motto = ''Veritas''Harvard's ''Veritas'' appears on the \n"
+ "university's arms; [[Heraldry|heraldically]] speaking, however, a 'motto' \n"
+ "is a word or phrase displayed on a scroll in conjunction with a shield of \n"
+ "arms. [https://books.google.com/books?\n"
+ "id=zkQWZaZqZfUC&pg=PA330&lpg=PA330#v=onepage&q&f=false Since 1692] \n"
+ "University [[seal (device)|seals]] have borne ''Christo et Ecclesiae'' \n"
+ "(for Christ and the Church) in this manner, arguably making that phrase \n"
+ "the university's motto in a heraldic sense. This legend is otherwise not \n"
+ "in general use today. |established = 1636An appropriation of £400 toward \n"
+ "a \"school or college\" was voted on October 28, 1636 (OS), at a meeting \n"
+ "which convened on September 8 and was adjourned to October 28. Some \n"
+ "sources consider October 28, 1636 (OS) (November 7, 1636 NS) to be the \n"
+ "date of founding. Harvard's 1936 tercentenary celebration treated \n"
+ "September 18 as the founding date, though 1836 bicentennial was \n"
+ "celebrated on September 8, 1836. Sources: meeting dates, {{cite \n"
+ "book|first=Josiah|last=Quincy|title=History of Harvard University \n"
+ "|year=1860 |publisher=Crosby, Nichols, Lee and Co.|location=117 \n"
+ "Washington Street, Boston}}, [https://books.google.com/books?\n"
+ "vid=OCLC11636583&id=KynqxH_4lGUC&pg=RA1-PA586&lpg=RA1-PA586 p. 586], \"At \n"
+ "a Court holden September 8th, 1636 and continued by adjournment to the \n"
+ "28th of the 8th month (October, 1636)... the Court agreed to give £400 \n"
+ "towards a School or College, whereof £200 to be paid next year....\" \n"
+ "Tercentenary dates: {{cite \n"
+ "news|url=http://www.time.com/time/\n"
+ "magazine/printout/0,8816,756722,00.html|date=September 28, \n"
+ "1936|accessdate=September 8, 2006|work=Time|title=Cambridge Birthday}}: \n"
+ "\"Harvard claims birth on the day the Massachusetts Great and General \n"
+ "Court convened to authorize its founding. This was Sept. 8, 1637 under \n"
+ "the Julian calendar. Allowing for the ten-day advance of the Gregorian \n"
+ "calendar, Tercentenary officials arrived at Sept. 18 as the date for the \n"
+ "third and last big Day of the celebration;\" \"on Oct. 28, 1636 ... £400 \n"
+ "for that 'school or college' [was voted by] the Great and General Court \n"
+ "of the [[Massachusetts Bay Colony]].\" Bicentennial date: {{cite web \n"
+ "|url=http://www.news.harvard.edu/gazette/2003/10.02/02-\n"
+ "history.html|publisher=Harvard University|title=Harvard Gazette: This \n"
+ "Month in Harvard History|date=September 2, 2003 |accessdate=September 15, \n"
+ "2006|author=Marvin Hightower}}, \"Sept. 8, 1836 - Some 1,100 to 1,300 \n"
+ "alumni flock to Harvard's Bicentennial, at which a professional choir \n"
+ "premieres \"Fair Harvard.\" ... guest speaker Josiah Quincy Jr., Class of \n"
+ "1821, makes a motion, unanimously adopted, 'that this assembly of the \n"
+ "Alumni be adjourned to meet at this place on September 8, 1936.'\" \n"
+ "Tercentary opening of Quincy's sealed package: ''The New York Times,'' \n"
+ "September 9, 1936, p. 24, \"Package Sealed in 1836 Opened at Harvard. It \n"
+ "Held Letters Written at Bicentenary\": \"September 8th, 1936: As the first \n"
+ "formal function in the celebration of Harvard's tercentenary, the Harvard \n"
+ "Alumni Association witnessed the opening by President Conant of the \n"
+ "'mysterious' package sealed by President Josiah Quincy at the Harvard \n"
+ "bicentennial in 1836.\" |mottoeng = Truth |type = [[Private \n"
+ "university|Private]] – [[Research]] |calendar = Semester |endowment = \n"
+ "$36.4 billion{{As of|2014|06|30}}. {{cite web | title = Harvard Endowment \n"
+ "Earns 15.4% Return for Fiscal 2014| work = The Wall Street Journal | url \n"
+ "= http://online.wsj.com/articles/harvard-endowment-earns-15-4-return-for-\n"
+ "fiscal-2014-1411506002 | accessdate=10 October 2014}} |president = [[Drew \n"
+ "Gilpin Faust]] |students = 21,000{{As of|2014|09|01}}. {{cite web | title \n"
+ "= Harvard at a Glance| work = Harvard University | url = \n"
+ "http://www.harvard.edu/harvard-glance | accessdate=27 November 2014}} \n"
+ "|undergrad = 6,700 |postgrad = 14,500 |staff = |faculty = 4,671{{Cite \n"
+ "book|last=Office of Institutional Research.|title=Harvard University Fact \n"
+ "Book|year=2009|chapter=Faculty|url=http:// \n"
+ "www.provost.harvard.edu/institutional_research/Provost_-_09_18-\n"
+ "19facuni.pdf}} (\"Unduplicated, Paid Instructional Faculty Count: 2,107. \n"
+ "Unduplicated instructional faculty count is the most appropriate count \n"
+ "for general reporting purposes.\") |city = [[Cambridge, \n"
+ "Massachusetts|Cambridge]] |state = [[Massachusetts]] |country = United \n"
+ "States |campus = [[Urban area|Urban]]{{Convert|210|acre|ha}} (Main \n"
+ "campus){{Convert|21|acre|ha}} (Medical campus)\n"
+ "{{Convert|360|acre|ha}} (Allston campus)\n"
+ "{{Convert|4500|acre|ha}} (other holdings) |sports = 42 varsity teams \n"
+ "|athletics = [[National Collegiate Athletic Association|NCAA]] [[Division \n"
+ "I (NCAA)|Division I]] – [[Ivy League]] |nickname = [[Harvard Crimson]] \n"
+ "|colors = {{color box|#A41034}} [[Crimson]]{{cite web|title=Color - \n"
+ "Identity Guidelines - Harvard Business \n"
+ "School|url=http://www.hbs.edu/marketing/color.html|publisher=Harvard \n"
+ "Business School|accessdate=26 September 2014}} |free_label = Student \n"
+ "newspaper |free = ''[[The Harvard Crimson]]'' |affiliations = [[National \n"
+ "Association of Independent Colleges and Universities|NAICU]]\n"
+ "[[Association of Independent Colleges and Universities in \n"
+ "Massachusetts|AICUM]][[Association of American Universities|AAU]]\n"
+ "[[Universities Research Association|URA]] |website = \n"
+ "{{URL|http://www.harvard.edu/|Harvard.edu}} |logo = [[File:Harvard \n"
+ "University logo.PNG|Harvard University logo (with its coat of arms)]] \n"
+ "|publictransit = [[Harvard (MBTA station)]] }} '''Harvard University''' \n"
+ "is a [[Private university|private]] [[Ivy League]] [[Doctoral \n"
+ "university|research university]] in [[Cambridge, \n"
+ "Massachusetts|Cambridge]], [[Massachusetts]], established in 1636. Its \n"
+ "history, influence and wealth have made it one of the most prestigious \n"
+ "universities in the world.{{cite book|title=Making Harvard Modern: The \n"
+ "Rise of America's \n"
+ "University|last1=Keller|first1=Morton|last2=Keller\n"
+ "|first2=Phyllis|publisher=Oxford University Press|isbn=0-19-514457-\n"
+ "0|quote=Harvard's professional schools... won world prestige of a sort \n"
+ "rarely seen among social institutions. (...) Harvard's age, wealth, \n"
+ "quality, and prestige may well shield it from any conceivable \n"
+ "vicissitudes.|year=2001|pages=463–481}}{{Cite book|title=How Harvard \n"
+ "Rules: Reason in the Service of Empire|quote=... [Harvard's] tremendous \n"
+ "institutional power and prestige (...) Within the nation's (arguably) \n"
+ "most prestigious institution of higher learning ...|chapter=Sexual \n"
+ "Shakedown|pages=326–336|year=1989|publisher=South End Press|isbn=0-\n"
+ "89608-284-9|editor1-first=John|last=Spaulding|first=Christina|editor-\n"
+ "last=Trumpbour}}{{cite web|url=http://www.bloomberg.com/news/2011-03-\n"
+ "10/harvard-mit-ranked-most-prestigious-universities-study-\n"
+ "reports.html|title=Harvard, MIT Ranked Most Prestigious Universities, \n"
+ "Study Reports|author=David Altaner|publisher=Bloomberg|date=March 9, \n"
+ "2011|accessdate=March 1, 2012}}{{cite book|title=Collier's \n"
+ "Encyclopedia|publisher=Macmillan Educational Co.|year=1986|quote=Harvard \n"
+ "University, one of the world's most prestigious institutions of higher \n"
+ "learning, was founded in Massachusetts in 1636.}}{{cite \n"
+ "web|last=Newport|first=Frank|title=Harvard Number One University in Eyes \n"
+ "of Public Stanford and Yale in second \n"
+ "place|url=http://www.gallup.com/poll/9109/harvard-number-one-university-\n"
+ "eyes-public.aspx|publisher=Gallup}} Established originally by the \n"
+ "[[Massachusetts General Court|Massachusetts legislature]] and soon \n"
+ "thereafter named for [[John Harvard (clergyman)|John Harvard]] (its first \n"
+ "benefactor), Harvard is the [[Colonial Colleges|United States' oldest \n"
+ "institution of higher learning]],{{cite book|first1=Frederick \n"
+ "|last1=Rudolph|title=The American College and \n"
+ "University|year=1961|page=3|isbn=0-8203-1285-1|publisher=University of \n"
+ "Georgia Press}} and the [[Harvard Corporation]] (formally, the \n"
+ "''President and Fellows of Harvard College'')";
final Pattern pattern = Pattern.compile(regex);
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