1

What is the easiest way to construct a java regular expression and pass it to a method that expects a String? Ideally something similar to SO JavaScript solution here.

System.out.println(System.getProperty(/* Regex here*/));

1 Answer 1

1

What is the easiest way to construct a java regular expression and pass it to a method that expects a String?

You can't. You can only use regular expressions with methods that are written to accept them, you can't use them with any method that just accepts a string (such as System.getProperty).

Methods accepting regular expressions, either explicitly as Pattern instances or implicitly as strings (like String#replaceAll), will say clearly that they do in their JavaDoc.

Sign up to request clarification or add additional context in comments.

2 Comments

So the solution to the above would be to fetch all with System.getProperties(), save to a List or a map, loop through it and match?
@Andrey: Specifically for system properties, yes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.