Java regex to check empty end of url

Program Description:

This program takes the end value from the url.

Program:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexEmptyEnd {
	public static String myurl = "http://ngdeveloper.com/regexpage&page=8372528";

	public static void main(String[] args) {

		String regex = "page=(.*?)$";

		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(myurl);
		if (matcher.find()) {
			String str = matcher.group(1);
			System.out.println("page is "+str);
		}
	}
}

 

Output:

page is 8372528

Thanks for reading this post………!!!

598 total views, 2 views today

About Mirthbees 679 Articles
Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.