java - Regex for matching pattern within quotes -
i have input info such as
some string 'hello' within 'and inside'
how can write regex quoted text (no matter how many times repeated) returned (all of occurrences).
i have code returns single quotes, want create returns multiple occurances:
string mydata = "some string 'hello' within 'and inside'"; pattern pattern = pattern.compile("'(.*?)+'"); matcher matcher = pattern.matcher(mydata); while (matcher.find()) { system.out.println(matcher.group()); }
find occurences me:
string mydata = "some '' string 'hello' within 'and inside'"; pattern pattern = pattern.compile("'[^']*'"); matcher matcher = pattern.matcher(mydata); while(matcher.find()) { system.out.println(matcher.group()); } output:
'' 'hello' 'and inside' pattern desciption:
' // start quoting text [^'] // characters not single quote * // 0 or infinite count of not quote characters ' // end quote java regex
No comments:
Post a Comment