MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1// Test string replace with regex
2
3// Basic regex replacement
4const str1 = 'hello world';
5const re1 = new RegExp('world');
6const result1 = str1.replace(re1, 'universe');
7console.log('Basic replace:', result1);
8
9// Test with global flag
10const str2 = 'foo bar foo baz';
11const re2 = new RegExp('foo', 'g');
12const result2 = str2.replace(re2, 'qux');
13console.log('Global replace:', result2);
14
15// Test without global flag (should replace only first)
16const str3 = 'foo bar foo baz';
17const re3 = new RegExp('foo');
18const result3 = str3.replace(re3, 'qux');
19console.log('Non-global replace:', result3);
20
21// Test with regex pattern (digits)
22const str4 = 'I have 2 apples and 3 oranges';
23const re4 = new RegExp('[0-9]+', 'g');
24const result4 = str4.replace(re4, 'X');
25console.log('Replace digits:', result4);
26
27// Test with dot pattern
28const str5 = 'abc123def';
29const re5 = new RegExp('...', 'g');
30const result5 = str5.replace(re5, 'X');
31console.log('Replace with dot:', result5);
32
33// Test string replace (without regex) - should still work
34const str6 = 'hello world';
35const result6 = str6.replace('world', 'there');
36console.log('String replace:', result6);
37
38console.log('All replace tests passed!');