There are three ways to access JavaScript Object property.
someObject.propertyName
someObject['propertyName'] // with single quote '
someObject["propertyName"] // with double quote "
Spaces between the brackets, i.e., someObject[ 'propertyName' ]
or someObject[ "propertyName" ]
, are allowed.
To detect all properties of the object someObject
within a text file, I wrote the following regexes.
Regex regex = new Regex(@"someObject\.[a-zA-Z_]+[a-zA-Z0-9_]*");
to detect properties of the formsomeObject.propertyName
.regex = new Regex(@"someObject\[[ ]*'[a-zA-Z_]+[a-zA-Z0-9_]*'[ ]*\]");
to detect properties of the formsomeObject['propertyName']
.
But I couldn't write regular expression for the properties of the form someObject["propertyName"]
. Whenever I try to write "
or \"
within a regular expression visual studio gives error.
I found some regular expression in the internet to detect double quoted text. For example this. But I couldn't add \[
and \]
in the regex, visual studio gives error.
How the properties of the form someObject["propertyName"]
can be detected?
I'm using C# System.Text.RegularExpressions
library.