다음과 같은 문자열이 있습니다. "StorageGroup1 그룹 내에서 할당 할 수있는 예약이 없습니다. 총 330GB의 스토리지가 요청되었습니다."
그러나 때때로 나는 항상 정확한 문자열을 얻지는 못하지만 (그룹과 총 GB 번호가 변수 인) 정확한 문자열 그룹을 얻었을 때 해당 티켓을 적절한 그룹으로 라우팅 할 수 있음을 알고 있습니다. 그것을 구문 분석 한 다음 저장소 그룹과 번호를 꺼내는 가장 좋은 방법은 티켓을 만들 때 동적 일 수 있습니다.
var myString = "No reservation is available to allocate within the group StorageGroup1. Total 330 GB of storage was requested";
var myRegexp = /No reservation is available to allocate within the group StorageGroup(\d). Total (.*) of storage was requested/g;
var match = myRegexp.exec(myString);
if (match != null) {
var storageGroup = match[1];
var size = match[2];
}
당신은 당신의 필요에 따라 myRegexp를 다듬을 수 있습니다. 나는 단지 안전한쪽에 있도록 전체 문장을 넣었습니다. http://jsfiddle.net/xbvpsp19/
@ krispykream4의 댓글 이후 업데이트 : 그룹 이름이 변경 될 수있는 경우 다음을 사용할 수 있습니다.
var myString = "No reservation is available to allocate within the group StorageGroup1. Total 330 GB of storage was requested";
var myRegexp = /No reservation is available to allocate within the group (\w*)(\d). Total (.*) of storage was requested/g;
var match = myRegexp.exec(myString);
if (match != null) {
var storageGroup = match[1];
var groupName = match[2];
var size = match[3];
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다