Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Trying to find all the strings which include "min" or "min." or "m." or "m". How to do that?

It should be something like this: (min.\|min|m.|m). But it finds "m", not "min." in text "blablabla min.". I understand why it returns what it returns, but don't know how to write to work it correctly.

share|improve this question
Found problem. I've tried to use brackets at start ")", but I've made a mistake by writing "min.\" instead of "min\.". After that regex was throwing exception about bad brackets. So i thougth it was the wrong way. – PovilasP Jun 19 '12 at 20:47
Can't see the button to close this question or mark as answered – PovilasP Jun 19 '12 at 20:48
You need to write your solution as an answer (in the big square below the links to twitter, facebook, etc.) and not as a comment to be able to accept it. Since your own answer, you will also need to wait a couple of days before you can actually mark the answer as your solution. – Tomas Lycken Jun 19 '12 at 20:52
You'll want to add your solution above as an answer, then mark that as correct. – NickHeidke Jun 19 '12 at 20:52
Voted to close since there's no way this issue will occur to someone else. – slhck Jun 19 '12 at 21:31

closed as too localized by Oliver Salzburg, Luke, slhck, KronoS, Nifle Jun 19 '12 at 21:24

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

This regex should be efficient to use: m(in)?\.?

To also correctly check for word boundaries after your match use this pattern: m(in)?\.?\b?

A good source for information about regular expressions can be found here and here.

share|improve this answer
But how about priority? Firt I want it would return min., then min, than m., than m. If you write m(in)?\.?, which will be returned first? – PovilasP Jun 19 '12 at 20:58
I don't get what you mean with "priority". Regex are used for matching something. If you use this regex, it will match all lines containing m, m., min, or min.. Also, regex match greedy, so if your line contains min. then min. will be matched instead of min or m. – speakr Jun 19 '12 at 21:03
Actually, I think you are wrong, regex works from left to right and what finds first accepts as a match. For example, I have now a problem using (m(in)?\.?) for the string "15mi" it returns "15m". So I changed it to (m(in)?\.?)\b, but now string "15m." returns "15m", becuuse point is understood as the and of the string than using \b :( – PovilasP Jun 19 '12 at 21:21
Actually, no, the pattern is correct. You have to insert correct boundary checks of course. \b works if something follows afterwards but it doesn't work if your input ends with the dot since you enforce having a \b in the end. This means that "15mins.someword" will match min. but "15min." will correctly match min. Add another ? after the \b. I modified my answer accordingly. – speakr Jun 20 '12 at 11:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.