Campbell Ritchie wrote:
You can pass the entire line to a Scanner object, then you can get a Stream of matches from a regex. Look at this method. (Java9 only.) Use its return result's group() method to get a String, and the last line simply calls System.out.println():-
Campbell Ritchie wrote:There must be easier ways to do that, even with a regex. Have you come across the predefined character class \w?
Paul Clapham wrote:Well, in line 11 of that code you apply replaceAll to the input string (variable name w) and assign the result to a new variable named wnew.
Then at line 12 you apply replaceAll to the input string again, only with a different regex, and assign that result to the variable named wnew. This has the effect of discarding the result of line 11.
Anyway, with regex there's all kinds of unexpected things which can happen if you get it a bit wrong. So it would help if you showed us an example of an input string and the result of line 12. Also it would help if you told us what you expected instead.
Campbell Ritchie wrote:Don't know. Please give us some more details about the code in question.
Tim Moores wrote:It sounds like you're looking for a client-side HTTP proxy with filtering capabilities. http://paw-project.sourceforge.net/ is one such (very old) project; you are bound to find more if you search for something like "java http filtering proxy".