Michael Michael - 1 year ago 115
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 Source
'name[required]'.replace(/\[.*?\]/g, '')
// => "name"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download