Regex expression for extracting numbers followed by 'KGS' -


i identify , extract numeric values followed 'kgs' (no space between number , 'kgs'. strings might contain other numbers not followed 'kgs' should ignored. example:

this 123 sample (500kgs) string. 

500 should extracted.

i suggest using less strict pattern here since not validating, extracting values. right now, regex extract 56, 578.56 or 52,456 values, , values 2,400.56 won't matched.

use

/\d[\d.,]*(?=\s*kgs)/i 

see regex demo. or, capturing:

/(\d[\d.,]*)\s*kgs/i 

the result in group 1. see another demo.

the \d[\d.,]* match digit, , 0 or more digits, . or ,.

the /i modifier make regex case-insensitive. depending on regex flavor, may use inline version of modifier, (?i) - put @ pattern start.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -