Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression, Match Between Single Quotes after Certain String

Tags:

regex

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.

like image 448
weeksdev Avatar asked Nov 28 '25 18:11

weeksdev


2 Answers

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).

like image 67
KeyNone Avatar answered Nov 30 '25 22:11

KeyNone


RegExp: /(?<=(itemid:\s\')|(itemid:\'))([^\']*)(?=\')/gi

DEMO - http://regexr.com?37tfk

like image 27
Rohit Agrawal Avatar answered Nov 30 '25 23:11

Rohit Agrawal