Extract variables from String using Regular expression

Following are the examples to extract variables from a string using you can use it any programming language 

If you wish to match only lines beginning with abc, use

^abc

Variables that will be extracted are the following 


AP2.RSV1

AP1.RSV3

AP["234"].RSV3

AP3.RSV22

 

Variables that will be extracted are the following 

 

 

 

 

 

 

 

 

 

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP2.RSV3-AP1.RSV3=3 OR AP["234"].RSV3+AP3.RSV22=3') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP1.RSV2 - AP2.RSV2 GTE .5 or (AP2.RSV2 GTE 6.6 and AP1.RSV2 GTE AP2.RSV2)') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP1.RSV2 EQ 10 OR AP2.RSV2 EQ 10 OR AP3.RSV2 EQ 10 OR AP4.RSV2 EQ 10') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP1.RSV2 EQ 10 OR AP2.RSV2 EQ 10 OR AP3.RSV2 EQ 10 OR AP4.RSV2 EQ 10 OR AP5.RSV2 EQ 10') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP1.RSV2 EQ 10 OR AP2.RSV2 EQ 10 OR AP3.RSV2 EQ 10 OR AP4.RSV2 EQ 10 OR AP5.RSV2 EQ 10 OR AP6.RSV2 EQ 10') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP1.RSV2 EQ 10 OR AP2.RSV2 EQ 10 OR AP3.RSV2 EQ 10 OR AP4.RSV2 EQ 10 OR AP5.RSV2 EQ 10 OR AP6.RSV2 EQ 10 OR AP7.RSV2 EQ 10') />
<cfdump var="#matches#" label="Example REMatch" />

<cfset matches = REMatch('AP(\d+|(\["\d+\"]))\.\RSV\d+', 'AP["234"].RSV3AP["2344554"].RSV3AP2.RSV3-AP1.RSV3=3 OR AP["234"].RSV3+AP3.RSV234"].RSV32=3') />
<cfdump var="#matches#" label="Example REMatch" />

 

 

 

 

 

 

 

 

 

 

 

 


Tags:

Share:

Related posts