-5

How would I match the two numbers before the word "min"

Sample string:

15min

I would want to match:

15

Edit:

I've tried matching the pattern, but how do I get the two characters before?

\W*((?i)min(?-i))\W*
CMS
  • 285
  • 1
  • 4
  • 10
  • 2
    _This is too difficult for me, please give me the code_, this is what your question is saying right now, add your attempts. – Tushar Jan 28 '16 at 11:30
  • Because it's a terrible question... Juste open a simple regex tutorial... – vard Jan 28 '16 at 11:31
  • [How to Regex](http://regexone.com/) – vard Jan 28 '16 at 11:32
  • 1
    Yet something like this gets 36 upvotes.. http://stackoverflow.com/questions/5752829/regular-expression-for-exact-match-of-a-word – CMS Jan 28 '16 at 11:35
  • 2
    Hi @CMS. Note how old that post is, the site has evolved somewhat since 2011. Also - it shows that there are many old answers that basically answer your question. If you need to know what regex expression matches a digit, the link provided above will help. If you need to capture the group of digits preceding the literal `"min"` it will help too. Have a look at [how to ask](http://stackoverflow.com/help/mcve) for up to date guidance on the way to ask questions here to get the best help. – J Richard Snape Jan 28 '16 at 11:39
  • I can see you've now edited in what you've tried. Can you now explain what you thought that would do and what it matches on the input string `15min` vs. what you'd like to get? Also - would you like to extract single digit numbers as well (e.g. `5min`)? 3 digit numbers? spaces between number and `"min"`? Also - are you happy with how to extract a particular bracketed group in whatever environment you are implementing this in? – J Richard Snape Jan 28 '16 at 11:44

1 Answers1

0

Here's a regex that just extracts the first number in the string:

^\D*(\d+).*$

If the number must be in front of min, then you can write it as:

^\D*(\d+)min.*$
Bane Bojanić
  • 712
  • 1
  • 8
  • 20