자바 스크립트에 문자열이 있습니다.
const str = "bugfix/SOME-9234-add-company"; // output should be SOME-9234
const str2 = "SOME/SOME-933234-add-company"; // output should be SOME-933234
const str3 = "test/SOME-5559234-add-company"; // output should be SOME-5559234
그리고 SOME-..
첫 번째 -
문자 까지 추출하고 싶습니다 .
이 정규식을 사용하지만 작동하지 않았습니다. 올바른 정규식은 무엇입니까?
const s = "bugfix/SOME-9234-add-company";
const r1 = s.match(/SOME-([1-9])/);
const r2 = s.match(/SOME-(.*)/);
const r3 = s.match(/SOME-(.*)-$/);
console.log({ r1, r2, r3 });
예를 들어/(SOME-[\d]+)/g
정규식을 사용할 수 있습니다.
const strings = [
"bugfix/SOME-9234-add-company", // output should be SOME-9234
"SOME/SOME-933234-add-company", // output should be SOME-933234
"test/SOME-5559234-add-company" // output should be SOME-5559234
];
strings.forEach(string => {
const regex = /(SOME-[\d]+)/g;
const found = string.match(regex);
console.log(found[0]);
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다