Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40513

Regular Expression (Java)

How do I match the following string?

http://localhost:8080/MenuTest/index.action

The regex should return true if it contains "MenuTest" in the above pattern.

Cheers

Upvotes: 0

Views: 676

Answers (4)

Peter Boughton
Peter Boughton

Reputation: 112230

If you need to check if "MenuTest" appears at that specific position (i.e. after the host/port), then you can use:

^https?://[^/]++/MenuTest

Upvotes: 1

karim79
karim79

Reputation: 342765

Maybe you don't need a regex?

String url = "http://localhost:8080/MenuTest/index.action";    
boolean hasWhatImLookingFor = url.contains("MenuTest");

Upvotes: 9

Andrew Swan
Andrew Swan

Reputation: 13637

The regex you seek is simply "MenuTest", without the quotes. Unless the question is more complex than it appears?

Upvotes: 0

miccet
miccet

Reputation: 1900

Something along these lines? (untested)

Regex r = new Regex("MenuTest");
r.search("http://localhost:8080/MenuTest/index.action");
System.out.println(""+r.didMatch());

Upvotes: 0

Related Questions