regx quetsion
I am having problems coming up with a regx that will match the section of the string I am wanting. Can/will someone plesae help me? Here is what I am trying and it is not working.
publicstaticvoid main(String[] args){
String response ="ISA~00~ ~00~ ~ZZ~REMOVED~ZZ~REMOVED~200201~1137~<~00405~000000001~0~T~!|GS~PO~REMOVED~ORDRLS90~20060201~113744~000000001~X~004050|ST~850~0001|BEG~00~SS~12345ABC~~20060201|REF~11~7132901427~ATN|REF~V0~09.00|DTM~097~20060201~1137AM|SI~TI~TP~TX|SI~TI~RE~E|SI~TI~AA~W|SI~TI~TY~81G-|PID~S~~TI~AO~~~SO-RSQ~Y|N1~BY~~25~3176|SE~12~0001|GE~1~000000001|IEA~1~000000001|";
/**
* This is how I want to get the substring
* Begin with a '|GS' then at least one '~' then any number or chars followed by only one '|'
* therefore the subsring I hope to get is:
* |GS~PO~LOCALTELSWORDT ~ORDRLS90~20060201~113744~000000001~X~004050|
*/
String GSregex ="|(GS)(~+?).*(\\|{1})";
List list = getMatchingValues(GSregex, receivedEdiMessage);
//print out the list
for (Iterator iter = list.iterator(); iter.hasNext();){
String element = (String) iter.next();
System.out.println(GSregex);
System.out.println("\t"+element);
}
}
//gets the value of the regex out of a search string
private List getMatchingValues(String regex, String searchString){
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(searchString);
List list =new LinkedList();
while(matcher.find()){
list.add(matcher.group());
}
return list;
}
The problem is that when I run the above main I get
(\|GS)(~+?).*(\|{1})
|GS~PO~REMOVE~ORDRLS90~20060201~113744~000000001~X~004050|ST~850~0001|BEG~00~SS~12345ABC~~20060201|REF~11~7132901427~ATN|REF~V0~09.00|DTM~097~20060201~1137AM|SI~TI~TP~TX|SI~TI~RE~E|SI~TI~AA~W|SI~TI~TY~81G-|PID~S~~TI~AO~~~SO-RSQ~Y|N1~BY~~25~3176|SE~12~0001|GE~1~000000001|IEA~1~000000001|
and that's not what I want.

