10 examples of 'regex match until character' in JavaScript

Every line of 'regex match until character' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
111public advanceUntilRegExp(regex: RegExp): string {
112 const str = this.source.substr(this.position);
113 const match = str.match(regex);
114 if (match) {
115 this.position = this.position + match.index!;
116 return match[0];
117 } else {
118 this.goToEnd();
119 }
120 return '';
121}
72eatWhile(match: mixed): boolean {
73 let isMatched = this._testNextCharacter(match);
74 let didEat = false;
75
76 // If a match, treat the total upcoming matches as one token
77 if (isMatched) {
78 didEat = isMatched;
79 this._start = this._pos;
80 }
81
82 while (isMatched) {
83 this._pos ++;
84 isMatched = this._testNextCharacter(match);
85 didEat = true;
86 }
87
88 return didEat;
89}
170function currentCharMatchesRegex(currentChar: string, token: ITokenRegex): boolean {
171 const match = currentChar.match(token.regex);
172 return (match && match[0] === currentChar);
173}
96readRegexReturnCapture_(regex, index) {
97 if (this.atEnd()) {
98 return null;
99 }
100
101 const ret = this.readRegex(regex);
102 if (!ret) {
103 return null;
104 } else {
105 return ret[index];
106 }
107}
414function collectUntil(re) {
415 const matches = new RegExp(`^([^${re}]*)`).exec(input.substr(current))
416 next(matches[1].length)
417 return matches[1]
418}
324function currentCharMatchesRegex(currentChar, token) {
325 const match = currentChar.match(token.regex);
326 return (match && match[0] === currentChar);
327}
18getStringUntilNonEscapedChar(terminalRegex: RegExp | string): string {
19 // if (typeof terminalRegex === 'string') {
20 // }
21 const chars: string[] = [];
22 for (let i = this.pos; i < this.len + 1; i++) {
23 this.pos = i;
24 if (this.str.charAt(i) == "\\" && this.str.charAt(i + 1).match(terminalRegex)) {
25 i++;
26 this.pos = i;
27 } else if (this.str.charAt(i).match(terminalRegex)) {
28 break;
29 }
30 chars.push(this.str.charAt(i));
31 }
32 return chars.join("");
33}
101public advanceIfRegExp(regex: RegExp): string {
102 const str = this.source.substr(this.position);
103 const match = str.match(regex);
104 if (match) {
105 this.position = this.position + match.index + match[0].length;
106 return match[0];
107 }
108 return '';
109}
77readRegex(regex) {
78 const index = this.indexOf_(regex);
79 if (this.atEnd() || index == null || index.position != this.position_) {
80 return null;
81 }
82
83 this.position_ += index.length;
84 return index.results;
85}
67protected eatUntil(match: RegExp): string {
68 let i = 0;
69
70 while (!match.test(this._str.charAt(this._currLocation + i))) {
71 i++;
72 if (i + this._currLocation > this._strLength) {
73 break;
74 }
75 }
76
77 this._currLocation += i;
78 return this._str.substr(this._currLocation - i, i);
79}

Related snippets