Conditional Replace Rule
Want to replace N characters before or after a specific symbol based on its position? Regular find-replace can't do it, but conditional replace can.
This Feature Helps You
- Replace N characters before anchor:
photo_20241225.jpg- want to change the 5 characters before_topic, becomingpic_20241225.jpg - Replace N characters after anchor:
report_draft_v3.docx- want to change the 1 character after_vtofinal, becomingreport_draft_vfinal.docx - Delete all content before anchor:
[Repost]Original Article Title.txt- want to delete everything before](including]), keeping only the title - Delete all content after anchor:
Product_Intro_Internal_Confidential.pptx- want to delete everything after the first_, keeping onlyProduct_Intro
Conditional Replace vs Find Replace
| Scenario | Can Find Replace Do It? | How Does Conditional Replace Do It? |
|---|---|---|
Change all IMG to Photo | ✅ Yes | Find-replace is simpler |
Delete 4 characters before _ | ❌ No (characters before aren't fixed) | ✅ Target char _, mode "before 4 chars" |
Delete everything after first - | ❌ No (content after isn't fixed) | ✅ Target char -, mode "after all chars" |
Core Difference: Find-replace only changes fixed text, conditional replace uses a symbol as anchor to change specified number of characters before/after it (regardless of what those characters are).
Quick Start (3 Steps)
- Click "Add Rule" button → Select "Conditional Replace"
- Set three key items:
- Target Character: Symbol to use as anchor, like
_,-,] - Mode: Choose to replace content before or after anchor
- Replacement: What to change it to (leave empty to delete)
- Target Character: Symbol to use as anchor, like
- Preview first, confirm it's correct before applying
Detailed Examples
Example 1: Replace Specified Characters Before Anchor
❌ Original: photo_20241225.jpg, image_20241226.jpg, pic_20241227.jpg
😫 Problem: Prefixes before _ have different lengths (5, 5, 3 characters), but all want to be changed to img
✅ Operation:
- Target Character:
_ - Replacement:
img - Mode: Before all characters
- Match: First
✅ Result: img_20241225.jpg, img_20241226.jpg, img_20241227.jpg
Why this setup: Using
_as anchor, replace all content before it withimg. No matter what the original prefix is or how long, it's handled uniformly.
Example 2: Delete Specified Characters After Anchor
❌ Original: document_v1.pdf, report_v2.pdf, summary_v3.pdf
😫 Problem: Want to change version numbers v1, v2, v3 to final, but version numbers aren't fixed
✅ Operation:
- Target Character:
_v - Replacement:
_final - Mode: After N characters
- Character Count: 1
- Replace Target String: Checked
✅ Result: document_final.pdf, report_final.pdf, summary_final.pdf
Why this setup: Using
_vas anchor, replace the 1 character after it (version number), and check "Replace Target String" to also replace_vwith_final.
Example 3: Delete All Content After Anchor
❌ Original: Product_Plan_Internal_Discussion_Confidential.pptx, Meeting_Notes_Reference_Only_20241225.docx
😫 Problem: Want to keep only the topic name before the first _, don't need the notes after
✅ Operation:
- Target Character:
_ - Replacement: (leave empty)
- Mode: After all characters
- Match: First
- Replace Target String: Checked
✅ Result: Product_Plan.pptx, Meeting_Notes.docx
Why this setup: Using the first
_as anchor, delete it and everything after it. No matter how many_or how long the notes are, they'll all be cleaned up.
Parameters to Fill
Basic Settings
-
Target Character Character or string to use as anchor, like
_,-,[,_v(Can't be empty, otherwise nothing will change) -
Replacement What to replace with, like
img,final(Leave empty = delete)
Advanced Options (Don't need to touch, defaults work fine)
-
Mode Default is "Before N Characters". Determines which part to replace relative to target character:
- Before N Characters (default): Replace specified number of characters before target
- After N Characters: Replace specified number of characters after target
- Before All Characters: Replace all content before target
- After All Characters: Replace all content after target
-
Character Count When "Before N Characters" or "After N Characters" is selected, specify how many characters to replace here. Default is 1.
-
Match Default is "First", only processes the first occurrence of target character. If target character appears multiple times in filename:
- First (default): Only process the first one
- Last: Only process the last one
- All: Process all matches
-
Replace Target String Default unchecked, keeps the target character itself, only replaces content before/after it. When checked, will replace the target character together.
-
Ignore Extension Default checked, only changes filename, doesn't touch suffixes like
.pdf,.docx.
Common Questions
❓ When to use conditional replace vs find replace?
- Content to replace is fixed (like changing all
IMGtoPhoto) → Use find replace - Content to replace isn't fixed, but position relative to a symbol is fixed (like content before
_) → Use conditional replace
❓ What happens if target character isn't found?
Filename stays unchanged, rule skips files without the target character.
❓ What if I set N characters but there aren't N characters?
Rule processes up to the filename boundary without errors. For example, if set to "after 3 characters" but there are only 2 characters after anchor, it will only replace those 2.
❓ What's "Replace Target String" for?
Controls whether to replace the target character (anchor) together.
- Unchecked (default):
2024_data.txt, target_, replace年, mode "before all characters" →年_data.txt(keeps_) - Checked: Same settings →
年data.txt(_also replaced)
Notes:
- ⚠️ Preview before applying: Conditional replace logic is more complex than find replace, recommend previewing each time
- ⚠️ "Before/After All Characters" is powerful: Will delete lots of content, use carefully
- ⚠️ Target character should be specific enough: If
_appears multiple times in filename, consider using a longer string (like_v) as anchor
Advanced Tips
- ✅ Combine with "Find Replace": First use find replace to standardize format, then use conditional replace for position-based precise processing
- ✅ Combine with "Remove Text": Conditional replace handles "relative to a symbol" deletion, remove text handles "fixed position" deletion
- ✅ Use regex for complex scenarios: If you need "only change numbers" or more complex pattern matching, consider using Regular Expression
What to Check Out Next?
- Find Replace: Simple way to replace fixed text
- Remove Text: Delete content by fixed position
- Regular Expression: More flexible pattern matching and replacement