Sign in to follow this  

awk regex

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this