Hello how does java and regex group work. For ex. I want to match any text 'something'
, the way I'd match this is .+\\s+'(.+)'{1}
, how can I replace any text 'something' with something?
Meaning replace matched string with 1st matched group.
If you just want to remove the single quotes, the following will work.
yourString.replaceAll("'([^']+)'", "$1");
That will search for 2 quotes with text in between. And replace it with only the text.
System.out.println("any text 'something'".replaceAll("'([^']+)'", "$1"));
Prints any text something
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.