regex find number before word

How can I write a regex to match the number for a specific word i provide such as alpha, beta, gam

3 gam (5 beta, 2 alpha)
3 gam (2 alpha, 5 beta)
2 alpha (3 gam, 5 beta)
NewtonianBAsked:
Who is Participating?
 
jeromeeConnect With a Mentor Commented:
This should do it then.
    ($number) = /(\d+)\s+beta/;

Good luck!
0
 
jeromeeCommented:
Hi NewtonianB,
I'm not sure I understand your request but let me take a shot at it...

% cat /tmp/ee1
3 gam (5 beta, 2 alpha)
3 gam (2 alpha, 5 beta)
2 alpha (3 gam, 5 beta)
%  perl -ne'$type="alpha"; ($data)=/(\d+)\s+$type/; print "$data\n"' /tmp/ee1
2
2
2


0
 
silemoneCommented:
You could group:

^([0-9])([ a-z\(]+)([0-9])([ a-z]+)([0-9])([ a-z\)]+)$

and groups would be:$1, $3, $5
would give you all numbers
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
silemoneCommented:
You could group:

^([0-9])([ a-z\(]+)([0-9])([ a-z,]+)([0-9])([ a-z\)]+)$

and groups would be:$1, $3, $5
would give you all numbers
0
 
NewtonianBAuthor Commented:
I need an expression to get the number in front of beta no matter where it is in the string
0
 
silemoneConnect With a Mentor Commented:
I don't understand, Newtonian...
the pattern you gave was

num
(space)
alpha
(
num
(space)
apha
,
num
(space)
apha
)


Does this pattern change?
0
 
käµfm³d 👽Commented:
__NO POINTS__

I agree with jeromee  ( http:35235729 ).
0
 
jeromeeCommented:
Thanks kaufmed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.