Java examples for java.util.regex:Match Word
get Word Position from sentence via regex
/**//w w w. j a va 2 s . com * * Copyright (c) 2000-2014 All Rights Reserved. */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String word = "java2s.com"; System.out.println(getWordPos(word)); } public static String getWordPos(String word) { String pos = ""; if (word.matches(".*?/\\p{Alnum}+?")) { pos = word.substring(word.lastIndexOf("/"), word.length()); } return pos; } }