Hi All,
I am new to java regex.Please help me. Consider the below paragraph,
Paragraph :
Name abc
sadghsagh
hsajdjah Name
ggggggggg
!!!
Name ggg
dfdfddfdf Name
!!!
Name hhhh
sahdgashdg Name
asjdhjasdh
sadasldkalskd
asdjhakjsdhja
!!!
i need to split the above paragraph as blocks of text starting with Name and ending with !!! . Here I dont want to use !!! as the only delimiter to split the paragraph.I need to include the starting sequence (Name) also in my regex.
ie., my result api should looks like SplitAsBlocks("Paragraph","startswith Name","endswith !!!")
How to achieve this ,please anyone help me ...
Now i want the same output as Brito given ...but here i have added Name after "hsajdjah".Here it split the text as beow :
Name
ggggggggg
!!!
but i need
Name abc
sadghsagh
hsajdjah Name
ggggggggg
!!!
that is i have to match up Name which is at the starting of the line ,not in the middle .
please suggest me ...
Bart ...see the below input case for your code ...
i need to split the following using ur API with parameter start => Name and end => ! But the output varies ..i have only 3 blocks starts with Name and ends with ! . i have attached the output also .
String myInput = "Name hhhhh class0"+ "\n"+
"HHHHHHHHHHHHHHHHHH"+ "\n"+
"!"+ "\n"+
"Name TTTTT TTTT"+ "\n"+
"GGGGGG UUUUU IIII"+ "\n"+
"!"+ "\n"+
"Name JJJJJ WWWW"+ "\n"+
"IIIIIIIIIIIIIIIIIIIII"+ "\n"+
"!"+ "\n"+
"RRRRRRRRRRR TTTTTTTT"+ "\n"+
"HHHHHH"+ "\n"+
"JJJJJ 1 Name class1"+ "\n"+
"LLLLL 5 Name class5"+ "\n"+
"!"+ "\n"+
"OOOOOO HHHH FFFFFF"+ "\n"+
"service 0 Name class12"+ "\n"+
"!"+ "\n"+
"JJJJJ YYYYYY 3/0"+ "\n"+
"KKKKKKK"+ "\n"+
"UUU UUU UUUUU"+ "\n"+
"QQQQQQQ"+ "\n"+
"!";
String[] tokens = tokenize(myInput, "Name", "!");
int n = 0;
for(String t : tokens) {
System.out.println("---------------------------\n"+(++n)+"\n"+t);
}
OutPut :
---------------------------
1
Name hhhhh class0
HHHHHHHHHHHHHHHHHH
!
---------------------------
2
Name TTTTT TTTT
GGGGGG UUUUU IIII
!
---------------------------
3
Name JJJJJ WWWW
IIIIIIIIIIIIIIIIIIIII
!
---------------------------
4
Name class1
LLLLL 5 Name class5
!
---------------------------
5
Name class12
!
Here i need to have only the Name at the starting of the line not at the middle ... How to add regex for this ...