Michael Michael - 27 days ago 8
Javascript Question

Remove square bracket with inner content in JavaScript

How can I remove all characters starting from a square bracket in JavaScript or jQuery?

For example:

name[required]
becomes
name
.

Answer
'name[required]'.replace(/\[.*?\]/g, '')
// => "name"