Has Prefix
Checks if a string starts with a specified prefix, returning true or false.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- String - The string to check.
- Prefix - The prefix to look for at the beginning of the string.
Options
This node does not have configurable options.
Output
- Result - Boolean value:
trueif string starts with prefix,falseotherwise.
How It Works
The Has Prefix node checks if a string begins with the specified prefix:
- Case-sensitive: "Hello" and "hello" are different
- Exact match: Prefix must match exactly from the start
- Returns boolean: true if starts with prefix, false otherwise
- Empty prefix: Always returns true
Usage Examples
Example 1: Check URL Protocol
- String:
"https://example.com" - Prefix:
"https://" - Result:
true
Example 2: Validate Phone Number Format
- String:
"+1-555-1234" - Prefix:
"+1" - Result:
true
Example 3: Check File Path
- String:
"/home/user/documents" - Prefix:
"/home" - Result:
true
Example 4: Case Sensitivity
- String:
"Hello World" - Prefix:
"hello" - Result:
false(lowercase 'h')
Example 5: Prefix Not Matching
- String:
"Hello World" - Prefix:
"Goodbye" - Result:
false
Tips
- Use for protocol validation (http://, https://, ftp://)
- Great for path validation (check if starts with /home, C:, etc.)
- Useful for format validation (phone numbers, IDs, codes)
- Search is case-sensitive - use Lowercase node first for case-insensitive check
- More specific than Includes - only checks the beginning
- Use with If node for conditional routing
Common Errors and Solutions
Error: Returns false when prefix should match
- Cause: Case sensitivity mismatch
- Solution: Convert both to same case before checking:
1. Lowercase both string and prefix
2. Then use HasPrefix
Error: Extra spaces causing mismatch
- Cause: Leading whitespace in string
- Solution: Use Trim node first to remove leading whitespace
Practical RPA Examples
Example: Validate URL Protocol
String: ${msg.url}
Prefix: "https://"
Result: true/false
Action: If false, prepend "https://"
Example: Filter Files by Directory
String: ${msg.filePath}
Prefix: "/var/log/"
Result: true
Action: Process only log files
Example: Validate Customer ID Format
String: ${msg.customerId}
Prefix: "CUST-"
Result: true/false
Action: If false, show format error
Example: Check Email Domain
String: ${msg.email}
Prefix: "admin@"
Result: true
Action: Route to admin queue
Example: Identify Product Category
String: ${msg.productCode}
Prefix: "ELEC-"
Result: true
Action: Electronics category
Example: Detect System Path
String: ${msg.path}
Prefix: "C:\\"
Result: true
Action: Windows system path detected
Pattern: Multi-Condition Routing
Route based on different prefixes:
Check 1: HasPrefix "ERROR-" → Route to error handler
Check 2: HasPrefix "WARN-" → Route to warning handler
Check 3: HasPrefix "INFO-" → Route to info handler
Pattern: Protocol Normalization
Ensure URLs have protocol:
Step 1: HasPrefix "http://" or "https://"
Step 2: If false, prepend "https://"
Result: Normalized URL with protocol
Pattern: Path Validation
Validate file paths:
Linux: HasPrefix "/"
Windows: HasPrefix "C:\\" or "D:\\"
Network: HasPrefix "\\\\"
Case-Insensitive Prefix Check
For case-insensitive matching:
Step 1: Lowercase on input string
Step 2: Lowercase on prefix
Step 3: HasPrefix check
Result: Case-insensitive prefix match
Combining with HasSuffix
Check both start and end:
Example: Validate email format
1. HasPrefix - should not start with "@"
2. HasSuffix - should end with ".com"
Both checks must pass