DD
DevDash

Regex for Makefile Target

Regex Pattern

^[a-zA-Z0-9_.-]+\s*:(?!=)

Makefile target definition (name followed by colon)

Quick Answer

The regex pattern for makefile target is `^[a-zA-Z0-9_.-]+\s*:(?!=)`. Makefile target definition (name followed by colon). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
build:✓ Matches
test:✓ Matches
clean:✓ Matches
all:✓ Matches
build command✗ No match
# comment✗ No match
VAR=value✗ No match

Code Examples

javascript

const regex = /^[a-zA-Z0-9_.-]+\s*:(?!=)/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-zA-Z0-9_.-]+\s*:(?!=)'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-zA-Z0-9_.-]+\s*:(?!=)/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-zA-Z0-9_.-]+\s*:(?!=)/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-zA-Z0-9_.-]+\\s*:(?!=)";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.