Reputation: 23
I´m trying to match the following sentence
ldcValue = 0.00
The regex i´m trying to create must match:
I have tried this regex:
if(match(line, "/(\<(ldc)\w*)(\t| )+(\=|>|<|>=|<=)\(\t| )*(\<(ldc)\w*)|\w*") > 0){
print "match: "substr($0, RSTART, RLENGTH);
}
but didn't match.
Input examples
ldcValue > 0.00
ldcValue = 0
ldblValue = ad_value / llDias
ldcValue = ad_Value * ldblFator
Expected output matched:
ldcValue > 0.00
ldcValue = 0
What is the correct regex?
Thanks.
Upvotes: 0
Views: 69
Reputation: 189317
In Awk, put either quotes or slashes around your regex, but not both. Your current attempt requires a literal slash before the first ldc
.
Also, traditional Awk does not typically support \w
which is a Perl extension.
Try
/\<ldc[A-Za-z0-9_]+[ \t]*([><]=|[<>=])[ \t]*(ldc[A-Za-z0-9_]|[0-9]+(\.[0-9]*)?d?)/
Your problem statement vaguely sounds like you need a proper parser, not just a regex, though.
Upvotes: 1