Shilpi Agrawal
Shilpi Agrawal

Reputation: 615

What will be the regular expression for this?

I have a string of "[195] shilpi is good girl [134]" how can i escape the [195] and [134] i tried many things but its not working out, i think because of [ ] this type of bracket as we use these brackets in regexp itself any help will be helpful.

Upvotes: 0

Views: 31

Answers (1)

Amit Badheka
Amit Badheka

Reputation: 2672

You can try the regex (\[\w+\])

str = '[195] shilpi is good girl [134]'
regex = /(\[\w+\])/
gsubed_str = str.gsub(regex, "")

The output of gsubed_str is " shilpi is good girl " which is what I assume you needd

Upvotes: 1

Related Questions