awk regex

Started by
4 comments, last by xyuri 18 years ago
I dont know if anyone on these forums will be able to help me with awk, but its worth a shot ... I am just trying to validate an ID number with regex in awk, but even though it works fine with other regex tools it simply wont with awk, which is really starting to cheese me off right now. just a simple function: ##################################################################### function chkForm_Id(s) { #check that id meets standard form return s ~ /^\d*$/; } using it like "chkForm_Id(123)", and it works fine if i take either (or both) the carat and dollar symbols out, but this should work fine. Would anyone like to educate me as to what is messing up here? Any help will be greatly appreciated. Thanks.
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Advertisement
use /^[0-9]+$/
Quote:Original post by xyuri
function chkForm_Id(s) {
#check that id meets standard form
return s ~ /^\d*$/;
}


Feh. the backslash-d thing is a PERL pattern-matching expression, not a real regex. Stephen Kleene rolls over in his grave every time some one claims their line noise is a program in that "language."

You have to stick to real regular expressions using tools like awk, sed, and grep.

Stephen M. Webb
Professional Free Software Developer

Thank you both very much for your responses. I have been doing a fair amount of regex since yesterday and have got more used to this "propper" regex expressions :) Thank you.
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Another quick one though ... in a range like [1-50] why will [1-99] work but [1-100] wont? I need to check -1 up to 100 but this has got me :(
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Quote:Original post by xyuri
Another quick one though ... in a range like [1-50] why will [1-99] work but [1-100] wont? I need to check -1 up to 100 but this has got me :(


nevermind, found my answer. sorry to anyone readin this thread ;)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend

This topic is closed to new replies.

Advertisement