user8478502
user8478502

Reputation: 33

extracting a word between brackets using regex pattern

Am using this tutorial to create regular expression for one of my task with input string as:

[Begin] { (GetLatestCode)

Trying to extract string between brackets i.e. trying to extract GetLatestCode for which I made the following:

(?<=\[Begin\]\s{\s\()\w+(?=\))     //returns GetLatestCode

But this solution does not seem to work when I have multiple spaces around the curly brace.

[Begin]    {            (GetLatestCode)     //does not work

Upvotes: 0

Views: 44

Answers (1)

ryangoree
ryangoree

Reputation: 1934

If you need to account for 0 or more spaces, add a * after each space:

(?<=\[Begin\]\s*{\s*\()\w+(?=\))

If you need to account for 1 or more, use a +:

(?<=\[Begin\]\s+{\s+\()\w+(?=\))

Upvotes: 1

Related Questions