Reputation: 4355
I am trying to match string between single quotes directly after another specific string. I created the following regular expression but it doesn't meet my needs if there is more than one property on a given line.
(?<=itemId:)(.*)'(.*)'
I am trying to match the string between single quotes after itemId in the following example:
looking to match:reasonFldSt
{
itemId: 'reasonFldSt',
xtype: 'fieldset',
layout: 'hbox',
width: 550,
margin: myMargin,
Looking for same string when there is more than one property on a line
Looking to match:minDebitFld
{ itemId: 'minDebitFld', fieldLabel: 'Min Bal', xtype: 'numberfield' },
Edit: I am using the built in find function in Visual Studio IDE that supports regular expressions to query.
Upvotes: 3
Views: 3132
Reputation: 5490
RegExp: /(?<=(itemid:\s\')|(itemid:\'))([^\']*)(?=\')/gi
DEMO - http://regexr.com?37tfk
Upvotes: 2
Reputation: 9150
Use
/itemId:\s?'(.+?)'/g
This way you only go for the value of itemId
. Global-flag is optional, depends whether your input is on one line or on multiple lines.
See the example@regex101.
Since you're using VisualStudios search function you have to omit the delimiters and the flag:
itemId:\s?'(.+?)'
If you want to exclude the term itemId from your search result you can use
(?<=itemId:\s?)'.+?'
This way VS will mark only the contents of the value, including both '
(tested in VS2012).
Upvotes: 3