Search code examples
javaregexmatchingdollar-sign

Java: How would I go about filtering a String with regex to find a specific charset?


I'm reading from a text file and I'm trying to filter:

::Tile(1,8), 92, water.png

so that it can find:

92, water.png

I have done this with:

Matcher m =Pattern.compile("\\),\\s([\\d+\\s*,\\s*\\w+\\s*]+)").matcher(statement);

where statement is the original String

However, when I use:

::Tile(1,8), 92b, water.png

as the original String, it completely ignores the intended regex match and gives:

92b, water.png

I've tried using the $ sign at the end to no avail. I've tried getting around using the + at the end of the regex inside ([...]) which doesn't help either.

Thanks for your time.


Solution

  • \\),\\s(\\d+\\s*,\\s*[\\w.]+\\s*)
    

    Guess you wanted this.[] is not what you think.It is a character class.Defining a pattern inside it is useless.See demo.

    https://regex101.com/r/gT6vU5/10