Regex extract only the closest numbers at both sides of a word (word boundaries?)

Hi,
I want to retrieve only numbers (can have a dot or coma)  that are just before or after one (see below) specific word ( "size" in this case).

123 size 23456 bbb    ->  123  and 23456
aa 123size23456             ->  123 and 23456
1.234 size 55.567       -> 1234 (or 1.234) and 55567
1234 size forget  345            -> 1234
aa12 size 14587          -> 14587

The ideal was to use the expression for several words  as    ?:size|area|length and also ignore characters not belonging to alphabet as space, /,-    ( example "1245/size/ 12"   would return   1245    12) if not too complex!
Can you help me?
novreisbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
This regex pattern seems to come close:
(\d[0-9.]*\d)?\s*size\s*(\d[0-9.]*\d)?

Open in new window

With your data, it parsed the following:
Match 0 Start(0) Length(14) 
	SubMatch 0: 123
	SubMatch 1: 23456

Match 1 Start(23) Length(12) 
	SubMatch 0: 123
	SubMatch 1: 23456

Match 2 Start(37) Length(17) 
	SubMatch 0: 1.234
	SubMatch 1: 55.567

Match 3 Start(56) Length(10) 
	SubMatch 0: 1234
	SubMatch 1: 

Match 4 Start(81) Length(13) 
	SubMatch 0: 12
	SubMatch 1: 14587

Open in new window

Question: In the last line, why aren't you getting the 12?
0
aikimarkCommented:
This pattern does not pick up the aa12 in the last line of your data.
\b(\d[0-9.]*\d)?\s*size\s*(\d[0-9.]*\d)?\b

Open in new window


please post some more examples of non-space characters used as delimiters.
0
aikimarkCommented:
When using this pattern:
\b(\d[0-9.]*\d)?\W*size\W*(\d[0-9.]*\d)?\b

Open in new window

the space delimited strings still parse correctly as well as this:
123 /size/ 23456 bbb
1245/size/ 12

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

novreisbAuthor Commented:
Hi aikimark,
Thank you very much by the solution! Just one very small aspect was not contemplated! The hypothesis of having more than one "keyword". But it is not relevant!
Rgrds
0
novreisbAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for novreisb's comment #a40239982

for the following reason:

The solution is not mine  and was my mistake , so I ask you to correct!
0
aikimarkCommented:
as far as different 'keywords' is concerned, you would just replace the "size" part of the pattern.  If you have a limited number of such keywords, they can be part of the regex pattern.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

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.