Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Created August 18, 2020 12:26
Show Gist options
  • Save fzn0x/51ed2c0d2032280bf48f8be65b24eb92 to your computer and use it in GitHub Desktop.
Save fzn0x/51ed2c0d2032280bf48f8be65b24eb92 to your computer and use it in GitHub Desktop.
Get string between two strings in java
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ASUS
*/
public class HelloWorld{
public static final int INDEX_NOT_FOUND = -1;
public static void main(String []args){
String name[] = new String[1000];
Pattern pattern = Pattern.compile("##(.*?)##", Pattern.DOTALL);
Matcher matcher = pattern.matcher("Hello ##wkwkwk## ##Ngamkakwk##");
int i = 0;
while (matcher.find()) {
name[i++] = matcher.group(1);
}
name = Arrays.stream(name)
.filter(s -> (s != null && s.length() > 0))
.toArray(String[]::new);
System.out.println(name.length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment