[SOLVED] grep for a string with both letters and digits...
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
^ Beware of what you call "word". Generally, in the regex world, a word is composed of characters [A-Za-z0-9_] but you seem to consider that a word is everything except space character.
So with your last regex, "5apples.3strawberries" and "1A|3B" and "1r,3d" are only one-word matches. Some people would have considered them being 2-word matches.
Moreover, as a side-effect, you include final punctuation signs inside your matches (for example: "t3st." matches inside "this is a t3st.", not just "t3st")
Depending on what you want, you may keep your regex or use one of the suggestions below:
Much simpler (and more readable) to use a more appropriate tool. awk for example is usually a better fit for field (i.e. "word") based processing.
And the regex handling is more flexible - use of logical AND for example.
The OP only wants the matching "word", not the entire record. ...
With this InFile ...
Code:
Four4 score and se7ven 777 years ago our fath22ers brought forth
on this continent a 88new nation, conceived in liberty,
and 99dedicated to the proposition99 that all men are cre5ated equal.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.