EditPadPro正则匹配需求:仅匹配POLYLINE、TYPE=0x6、RoadID
Got it, let's get that regex working properly for you! Your current pattern only catches the first two parts of what you need—we'll expand it to ensure it matches only the blocks that include all three: [POLYLINE], Type=0x6, and RoadID.
Solution 1: Fixed Order (Matches Your Example)
If the elements always appear in the order [POLYLINE] → Type=0x6 → RoadID (like your sample text), use this regex:
\[POLYLINE\].*?Type=0x6.*?RoadID.*?\[END\]
Breakdown:
\[POLYLINE\]: Explicitly matches the opening tag (brackets are escaped because they’re special regex characters).*?: Non-greedy match for any characters—stops at the next target instead of grabbing everything in the documentType=0x6: Matches the exact type value you needRoadID: Ensures the block includes this identifier.*?\[END\]: Finishes matching until the closing[END]tag
Solution 2: Flexible Order (Elements Can Be Anywhere)
If Type=0x6 and RoadID might appear in any order within the [POLYLINE] block, use positive lookaheads to enforce all three conditions are met:
\[POLYLINE\](?=.*?Type=0x6)(?=.*?RoadID).*?\[END\]
Breakdown:
(?=.*?Type=0x6): Positive lookahead—checks thatType=0x6exists somewhere after[POLYLINE]without consuming characters(?=.*?RoadID): Another lookahead to confirmRoadIDis present in the block- The rest works the same as Solution 1, capturing the full block from start to end
Handling Multi-Line Blocks
If your [POLYLINE] blocks span multiple lines, replace .*? with [\s\S]*? (this matches any whitespace or non-whitespace character, including newlines):
\[POLYLINE\](?=[\s\S]*?Type=0x6)(?=[\s\S]*?RoadID)[\s\S]*?\[END\]
Alternatively, you can enable the "Dot matches newlines" option in EditPad Pro's regex settings—this makes .*? include line breaks too.
Why Your Original Regex Didn't Work
Your pattern \[POLYLINE]\W+(?:\w+\W+0x6) only matches up to the 0x6 part and doesn’t check for RoadID at all. It also stops short of capturing the full block, which is why you weren't getting the complete matches you need.
How to Use This in EditPad Pro:
- Open the Find dialog (Ctrl+F)
- Switch to the Regular expression mode
- Select your preferred regex flavor (Perl, Java, or .NET—all support these patterns)
- Paste the regex from above and hit "Find Next"
内容的提问来源于stack exchange,提问作者JohnWeck

