Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript first and last name on fullname regex

var rex = /^((w*)s?).*?(s?(w*)[^ws]*)$/
var v = ["Luis Caldas Neto", "Luis Neto!", "Luis Neto", "Luis G Neto", "Luis"]
// Running tests
JSON.stringify( 
  v.map( v => rex.exec(v.trim()).filter((x, i, a)=>(i===2||i===4))) 
)
// Tests sould be return values:
// ["Luis","Neto"],["Luis","Neto"],["Luis","Neto"],["Luis","Neto"],["Luis",""]

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #fullname #regex
ADD COMMENT
Topic
Name
3+4 =