w

Text Replacer Examples

This page provides practical examples of how to use the Text Replacer tool for common tasks. Each example includes the pattern, replacement text, and expected results.

Text Formatting Examples

Name Formatting

Convert "First Last" to "Last, First"

Pattern: \b(\w+)\s+(\w+)\bReplacement: $2, $1

Input:

John Doe
Jane Smith
Bob Johnson

Output:

Doe, John
Smith, Jane
Johnson, Bob

Phone Number Formatting

Format phone numbers consistently

Pattern: (\d{3})(\d{3})(\d{4})Replacement: ($1) $2-$3

Input:

1234567890
9876543210
5551234567

Output:

(123) 456-7890
(987) 654-3210
(555) 123-4567

Date Format Conversion

Convert dates from YYYY-MM-DD to MM/DD/YYYY

Pattern: (\d{4})-(\d{2})-(\d{2})Replacement: $2/$3/$1

Input:

2023-12-25
2024-01-01
2024-06-15

Output:

12/25/2023
01/01/2024
06/15/2024

Code Refactoring Examples

Function Renaming

Rename function calls across code

Pattern: oldFunction\(Replacement: newFunction(

Input:

function processData() {
  oldFunction(data);
  return oldFunction(result);
}

Output:

function processData() {
  newFunction(data);
  return newFunction(result);
}

Variable Naming Convention

Convert camelCase to snake_case

Pattern: ([a-z])([A-Z])Replacement: $1_$2

Input:

firstName
lastName
emailAddress
phoneNumber

Output:

first_name
last_name
email_address
phone_number

Import Statement Updates

Update import paths

Pattern: from ['"]old-package['"]Replacement: from 'new-package'

Input:

import { Component } from 'old-package';
import { utils } from 'old-package';

Output:

import { Component } from 'new-package';
import { utils } from 'new-package';

Data Processing Examples

CSV to Markdown Table

Convert CSV data to Markdown table format

Pattern: ^(.+),(.+),(.+)$Replacement: | $1 | $2 | $3 |

Input:

Name,Age,City
John,25,New York
Jane,30,Los Angeles
Bob,35,Chicago

Output:

| Name | Age | City |
| John | 25 | New York |
| Jane | 30 | Los Angeles |
| Bob | 35 | Chicago |

Remove Empty Lines

Clean up text by removing empty lines

Pattern: ^\s*$\nReplacement: (empty)

Input:

Line 1

Line 2

Line 3

Output:

Line 1
Line 2
Line 3

Extract Email Addresses

Find and format email addresses

Pattern: \b([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,})\bReplacement: [EMAIL: $1]

Input:

Contact us at support@example.com or sales@company.org

Output:

Contact us at [EMAIL: support@example.com] or [EMAIL: sales@company.org]

Content Management Examples

Add Line Numbers

Add line numbers to text

Pattern: ^Replacement: 1.

Input:

First item
Second item
Third item

Output:

1. First item
2. Second item
3. Third item

HTML Tag Removal

Remove HTML tags from content

Pattern: <[^>]+>Replacement: (empty)

Input:

<p>This is <strong>bold</strong> text.</p>

Output:

This is bold text.

Convert plain URLs to Markdown links

Pattern: (https?://[^\s]+)Replacement: [$1]($1)

Input:

Visit https://example.com for more info.

Output:

Visit [https://example.com](https://example.com) for more info.

Advanced Pattern Examples

Credit Card Number Masking

Mask credit card numbers for security

Pattern: (\d{4})\d{8}(\d{4})Replacement: $1********$2

Input:

Card: 1234567890123456
Card: 9876543210987654

Output:

Card: 1234********3456
Card: 9876********7654

JSON Key Renaming

Rename JSON object keys

Pattern: "oldKey":Replacement: "newKey":

Input:

{
  "oldKey": "value1",
  "otherKey": "value2",
  "oldKey": "value3"
}

Output:

{
  "newKey": "value1",
  "otherKey": "value2",
  "newKey": "value3"
}

Multi-line Comment Removal

Remove multi-line comments from code

Pattern: /\*[\s\S]*?\*/Replacement: (empty)

Input:

function test() {
  /* This is a comment
       that spans multiple lines */
  return true;
}

Output:

function test() {
  return true;
}

Configuration File Examples

Environment Variable Updates

Update configuration values

Pattern: DATABASE_URL=.*Replacement: DATABASE_URL=postgresql://localhost:5432/mydb

Input:

DATABASE_URL=mysql://old-host:3306/old-db
API_KEY=secret123

Output:

DATABASE_URL=postgresql://localhost:5432/mydb
API_KEY=secret123

Version Number Updates

Update version numbers in package files

Pattern: "version":\s*"[^"]*"Replacement: "version": "2.0.0"

Input:

{
  "name": "my-app",
  "version": "1.0.0",
  "description": "My application"
}

Output:

{
  "name": "my-app",
  "version": "2.0.0",
  "description": "My application"
}

Tips for Using Examples

Testing Patterns

  1. Start with the provided examples
  2. Modify patterns to match your specific needs
  3. Test with small samples before processing large text
  4. Use the preview feature to verify matches

Customizing Examples

  • Adjust patterns for different data formats
  • Combine multiple patterns for complex transformations
  • Save successful patterns in the history for reuse
  • Document custom patterns for future reference

Best Practices

  • Always backup original data
  • Test patterns incrementally
  • Use specific patterns to avoid unintended matches
  • Validate results before applying to production data

Ready to try these examples? Open the Text Replacer tool and start experimenting!

Was this page helpful?