Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Well I have tred all sorts of things, All of them on regexr.com. It is easy to match 1 "-"
But matching 2 a little harder. This is the closest I have come so far
Which tool are you using to apply the expression? Perl or sed or something else? In other words, which type of regular expression do you wish to use?
The methods of writing character classes will vary. In perl and perl-compatible regular expressions an alphanumeric character can be written as \w or [[:alpha:]]. In POSIX, it is written as [[:alpha:]] Then there is also Extended POSIX.
In each style there are modifiers to match sequences. {1,} + * and so on. But not the same in all styles.
Last edited by Turbocapitalist; 07-01-2019 at 10:15 PM.
As mentioned, \w is for a single character - to match a word, you need the "+" modifier which says "one or more". So your last attempt above is very close.
Note that \w is not strictly the same as [[:alpha:]] - if you use underscores for example. I do regularly in filenames in lieu of spaces.
an alphanumeric character can be written as \w or [[:alpha:]]. In POSIX, it is written as [[:alpha:]]
To be strict [[:alpha:]] is a LETTER (alphabetic character in the current locale), an alphanumeric one is [[:alnum:]]
\w is a synonym for [_[:alnum:]], so the class alnum extended with an underscore.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.