Skip to content

Instantly share code, notes, and snippets.

@varrix
Created April 10, 2016 19:53
Show Gist options
  • Save varrix/e307a0b24c263b67670d698546615fb5 to your computer and use it in GitHub Desktop.
Save varrix/e307a0b24c263b67670d698546615fb5 to your computer and use it in GitHub Desktop.
Simple no-dependency character sequence matching using quotations in Java. Source: http://stackoverflow.com/a/1473198
public static void main(String[] args) {
String line = "/cmd \"test\"";
Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(line);
while (m.find()) {
System.out.println(m.group(1));
}
}
@varrix
Copy link
Author

varrix commented Apr 10, 2016

Output: test

@varrix
Copy link
Author

varrix commented Dec 1, 2016

"This example assumes that the language of the line being parsed doesn't support escape sequences for double-quotes within string literals, contain strings that span multiple "lines", or support other delimiters for strings like a single-quote." - https://stackoverflow.com/users/3474/erickson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment