parse string to get word between quotes code example

Example 1: regex get string between quotes java

Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(line);
while (m.find()) {
  System.out.println(m.group(1));
}

Example 2: how to get a string in two quotes

#
# START of getting the substring
#
start = line.find("\"") + len("\"")
end = line.find("*\"")
substring = line[start:end]
print(substring)
plaintxt += substring
substring = ""
print(plaintxt)
#
# END of getting the substring
#

# This will find a string in the middle of two quotes 
# with a star at the end
# Like this: (START --->) " This is your string (END --->) *"

Tags:

Java Example