Skip to content

Instantly share code, notes, and snippets.

@jamesasu
Created September 30, 2024 05:37
Show Gist options
  • Save jamesasu/38409f2b636f764c17387bd4d41fe26d to your computer and use it in GitHub Desktop.
Save jamesasu/38409f2b636f764c17387bd4d41fe26d to your computer and use it in GitHub Desktop.
java-regex-negative-lookbehind-lookahead.java
Pattern newProjectPattern = Pattern.compile("(?<=before)(Stuff to actually find)(?=after)");
Matcher newProjectMatcher = newProjectPattern.matcher(str);
if (newProjectMatcher.find()) {
return newProjectMatcher.group(1).trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment