Difference between revisions of "Regular Expressions"

Jump to navigation Jump to search
653 bytes added ,  11:48, 12 November 2010
→‎Examples: Added "VMHBA LUN ID"
(Reworked page)
(→‎Examples: Added "VMHBA LUN ID")
Line 27: Line 27:
''' <code> (?<=\[)(.*?)(?=\]) </code> '''
''' <code> (?<=\[)(.*?)(?=\]) </code> '''


Matches everything between <code> [ </code> and <code> ] </code>, so for example...
Matches everything between <code> [ </code> and <code> ]</code>, so for example...
* <code> VMFS_SCSI_DS_01 </code> is matched from <code> [VMFS_SCSI_DS_01] My_VM/MyVM.vmdk
* <code> VMFS_SCSI_DS_01 </code> is matched from <code> [VMFS_SCSI_DS_01] My_VM/MyVM.vmdk


Its essentially done via three chunks of the regex...
Its essentially done via three chunks of the regex...
# <code> (?<=\[) </code>
# <code><nowiki> (?<=\[) </nowiki></code>
#* Requires that <code> [ </code> immediately proceeds the match
#* Requires that <code> [ </code> immediately proceeds the match
# <code> (.*?) </code>
# <code> (.*?) </code>
Line 37: Line 37:
# <code> (?=\]) </code>
# <code> (?=\]) </code>
#* Requires that <code> [ </code> immediately follows the match
#* Requires that <code> [ </code> immediately follows the match
=== VMHBA LUN ID ===
'''<code> (?<=:)([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$ </code>
Finds a number between 0 and 255 immediately after a <code>:</code> at the end of a line, specifically intended to get the LUN ID from a VMware canonical path, so for example...
* <code>13</code> is matched from <code>vmhba3:0:13</code>
Stepping through the regex...
# <code><nowiki> (?<=:) </nowiki></code>
#* Requires that <code> : </code> immediately proceeds the match
# <code>([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])</code>
#* Matches any number between 0 and 255
# <code>$</code>
#* Ensures that the proceeding match occurs at the end of a line

Navigation menu