I’ve started using the .match(Regex) method in my java program, but for now I’m just using a string (String regexString = new String("[^a-zA-Z0-9][^a-zA-Z0-9]*"); which is what I have so far, as an example). I know however I can use an actual regex (Regex pattern = new Regex() & the Pattern class then compile it (?) some how).
Is there an advantage to using Regex as a class and not just a string, in java? I’m quite used to bash scripting and there regexes are just ‘strings’ in the loosest sense, and there is no ability/need for a separate class, so I’m struggling to see where there is one here.
I would do what you think is simplest and clearest.
A
Patternis often used when the performance of a regex is critical. If you haven’t profiled your application and it has been shown to be an issue, using a plainStringis likely to be fine.