2

Is it possible to test for multiple substrings in the following string using contains()?

"details.php?news=13&action=main&menu_type=&option=single&news_id=4792&pub_no=50"   

For example, can I check for strcase="details.php", "news_id" to be checked at the same time using str.contains(strcase)?

I do not want to check like this: str.contains("details.php")&&str.contains("news_id"). because I want to check for both simultaneously: strcase="details.php ** news_id"

Like this statement :

str.replaceAll("\\<[^>]*>","");

can strip out tag "<?>".

1 Answer 1

5

string.contains() does not match regular expressions, so you cannot use it like str.replace().

You could use string.matches() though, as it does accept regular expressions.

str.matches(".*details\\.php.*news_id.*");

*Disclaimer* I suck at regular expressions, but that should be close to what you want.

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

2 Comments

Yep, looks good to me, as long as "details" really has to be the first thing in the string. Otherwise, you'll need another .* in there.
Just FYI, replace() doesn't use regexes either; it's replaceAll() you're thinking of.

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.