Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7535626
test_string_replace_regex.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_string_replace_regex.cjs
View Options
// Test string replace with regex
// Basic regex replacement
const str1 = 'hello world';
const re1 = new RegExp('world');
const result1 = str1.replace(re1, 'universe');
console.log('Basic replace:', result1);
// Test with global flag
const str2 = 'foo bar foo baz';
const re2 = new RegExp('foo', 'g');
const result2 = str2.replace(re2, 'qux');
console.log('Global replace:', result2);
// Test without global flag (should replace only first)
const str3 = 'foo bar foo baz';
const re3 = new RegExp('foo');
const result3 = str3.replace(re3, 'qux');
console.log('Non-global replace:', result3);
// Test with regex pattern (digits)
const str4 = 'I have 2 apples and 3 oranges';
const re4 = new RegExp('[0-9]+', 'g');
const result4 = str4.replace(re4, 'X');
console.log('Replace digits:', result4);
// Test with dot pattern
const str5 = 'abc123def';
const re5 = new RegExp('...', 'g');
const result5 = str5.replace(re5, 'X');
console.log('Replace with dot:', result5);
// Test string replace (without regex) - should still work
const str6 = 'hello world';
const result6 = str6.replace('world', 'there');
console.log('String replace:', result6);
console.log('All replace tests passed!');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 17, 12:08 PM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523931
Default Alt Text
test_string_replace_regex.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment