javascript - Regular Expressions - Select all before first whitespace character assuming it includes both characters and digits -


i've built little google maps widget speed process of people inputting address form, however, because seems google maps isn't particularly accurate when comes actual house numbers, i've added ability override / prepend house number selected location.

here's quick example...

i select location on map , returns: 13b main street, london, l0n d0n, united kingdom

which great, however, assuming person filling out form doesn't live @ 13b 13a, i'm trying use regular expression override / replace section of string.

i have following: /([^\s]+)/ selects first word or until first white space character again worked fine, until noticed google maps doesn't return building number meaning main street become replaced street if no building number returned.

so basically, i'm trying build regular expression meets following conditions.

it's first word (before whitespace character) , must either solely number or combination of both not characters.

thanks help!

also, if it's not ask if you're posting answer perhaps explain how regular expression constructed , parts checking what. thanks!

you can use regex match part of text must contain digit before first whitespace:

/^[a-za-z]*\d[a-za-z\d]*(?=\s)/ 

regex demo


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -