Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get rid of this "(" using regex?
    text
    copied!<p>I was moving along on a regex expression and I have hit a road block I can't seem to get around. I am trying to get rid of "(" in the middle of a line of text using regex, there were 2 but I figured out how to get the one on the end of the line. its the one in the middle I can hack out.</p> <p>Here is a more complete snippet of the file which I am search through.</p> <pre><code>ide1:0.present = "TRUE" ide1:0.clientDevice = "TRUE" ide1:0.deviceType = "cdrom-raw" ide1:0.startConnected = "FALSE" floppy0.startConnected = "FALSE" floppy0.clientDevice = "TRUE" ethernet0.present = "TRUE" ethernet0.virtualDev = "e1000" ethernet0.networkName = "solignis.local" ethernet0.addressType = "generated" guestOSAltName = "Ubuntu Linux (64-bit)" guestOS = "ubuntulinux" uuid.location = "56 4d e8 67 57 18 67 04-c8 68 14 eb b3 c7 be bf" uuid.bios = "56 4d e8 67 57 18 67 04-c8 68 14 eb b3 c7 be bf" vc.uuid = "52 c7 14 5c a0 eb f4 cc-b3 69 e1 6d ad d8 1a e7" </code></pre> <p>Here is a the entire foreach loop I am working on.</p> <pre><code>my @virtual_machines; foreach my $vm (keys %virtual_machines) { push @virtual_machines, $vm; } foreach my $vm (@virtual_machines) { my $vmx_file = $ssh1-&gt;capture("cat $virtual_machines{$vm}{VMX}"); if ($vmx_file =~ m/^\bguestOSAltName\b\s+\S\s+\W(?&lt;GUEST_OS&gt; .+[^")])\W/xm) { $virtual_machines{$vm}{"OS"} = "$+{GUEST_OS}"; } else { $virtual_machines{$vm}{"OS"} = "N/A"; } if ($vmx_file =~ m/^\bguestOSAltName\b\s\S\s.+(?&lt;ARCH&gt; \d{2}\W\bbit\b)/xm) { $virtual_machines{$vm}{"Architecture"} = "$+{ARCH}"; } else { $virtual_machines{$vm}{"Architecture"} = "N/A"; } } </code></pre> <p>I am thinking the problem is I cannot make a match to "(" because the expression before that is to ".+" so that it matches everything in the line of text, be it alphanumeric or whitespace or even symbols like hypens.</p> <p>Any ideas how I can get this to work?</p> <p>This is what I am getting for an output from a hash dump.</p> <pre><code>$VAR1 = { 'NS02' =&gt; { 'ID' =&gt; '144', 'Version' =&gt; '7', 'OS' =&gt; 'Ubuntu Linux (64-bit', 'VMX' =&gt; '/vmfs/volumes/datastore2/NS02/NS02.vmx', 'Architecture' =&gt; '64-bit' }, </code></pre> <p>The part of the code block where I am working with ARCH work flawless so really what I need is hack off the "(64-bit)" part if it exists when the search runs into the ( and have it remove the preceding whitespace before the (.</p> <p>What I am wanting is to turn the above hash dump into this.</p> <pre><code>$VAR1 = { 'NS02' =&gt; { 'ID' =&gt; '144', 'Version' =&gt; '7', 'OS' =&gt; 'Ubuntu Linux', 'VMX' =&gt; '/vmfs/volumes/datastore2/NS02/NS02.vmx', 'Architecture' =&gt; '64-bit' }, </code></pre> <p>Same thing minus the (64-bit) part.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload