Reputation: 23
I am trying to figure out how to create an expression for Sublime that can find in files when a variable (m_CastShadows) is 1 through 3 for a given sub-section of text (ParticleSystemRenderer:), but ignore that same variable name if it is in a different section (MeshRenderer:).
Each section begins with "--- !".
How would I find sections that begin with "ParticleSystemRenderer:" and includes m_CastShadow: [1-3]
?
In the below example text, the first "ParticleSystemRenderer:" block would be skipped, because "m_CastShadows" is 0, while the second would be matched, because "m_CastShadows" is 2.
My question is: What would be the expression to have Sublime return files where ONLY the "m_CastShadows" variable in any "ParticleSystemRenderer:" section of the file that is not zero and ignoring any other "m_CastShadows" variable it finds in other sections?
I tried the following expression to return all files that contain this string using the expression m_CastShadows: [1-3]
but that will return files where ANY "m_CastShadows" is not zero (not just the "ParticleSystemRenderer:" section ones).
Beyond that though I'm pretty lost with RegEx. I did try to build an expression at regexr.com, but could not figure out a working expression for this.
EXAMPLE TEXT:
--- !u!1 &75000372733
MeshRenderer:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000010438045922}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
--- !u!23 &23000010372327926
ParticleSystemRenderer:
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
--- !u!2 &23006841372327911
SomeOtherSection:
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 0
--- !u!23 &97320010372327543
ParticleSystemRenderer:
m_Enabled: 1
m_CastShadows: 2
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
--- !u!2 &23006841372327911
SomeOtherSection2:
m_Enabled: 1
m_CastShadows: 3
m_ReceiveShadows: 0
With the above example text I would expect Sublime to return the file if the "m_CastShadows" for ONLY the "ParticleSystemRenderer:" section is greater than 0. It would ignore the one in "MeshRenderer:" regardless of its value.
It would also not return the file if "m_CastShadows" for the "ParticleSystemRenderer:" section was changed to zero (again, regardless of what the one in the "MeshRenderer:" section was set to - or any other section of the file that happened to use the same variable name).
It is also worth noting that the file may contain multiple "ParticleSystemRenderer:" sections. As long as one of the "m_CastShadows" variables in one of those "ParticleSystemRenderer:" sections is greater than zero, I would want it to return the file.
Thanks in advance to you RegEx wizards for guidance in this!
Upvotes: 1
Views: 48
Reputation:
This is for your specific example
(?:\r?\n|^)ParticleSystemRenderer:.*\r?\n(?:[ ]{2,}.*\r?\n)*?[ ]{2,}m_CastShadows:[ ]*([1-9]\d*)
https://regex101.com/r/GVSWuZ/1
If your engine supports multi-line mode, use this
(?m)^ParticleSystemRenderer:.*\s*(?:^[ ]{2,}.*\s*)*?[ ]{2,}m_CastShadows:[ ]*([1-9]\d*)
https://regex101.com/r/wLmlAL/1
Upvotes: 2
Reputation: 27743
This expression might help you to design one:
(ParticleSystemRenderer:[\s\S]*)(m_CastShadows: [1-3])
This graph shows how it works:
Upvotes: 1