Hello! I'm pretty new to perl and trying to write a regex to match a sequence. Basically, I have a number of cells and for each cell, a number of pins. The pins are listed as :
Pin: U343.IN1 in
Pin: U713.INP out
Pin: U714.QN
The one with out at the end or with nothing at the end are the output pins that I want to match. So I got to:
/^[ ]+Pin:[ ]*([^\.]*)\.([^ ]*)$/
--> Matches " Pin: U714.QN"
$1 = U714
$2 = QN
and
/^[ ]+Pin:[ ]*([^\.]*)\.([^ ]*)[ ]out/
--> Matches " Pin: U713.INP out"
$1 = U713
$2 = INP
Is there a way to combine these two so that it matches both?
I tried using "|" to or them
^[ ]+Pin:[ ]*([^\.]*)\.([^ ]*)$|^[ ]+Pin:[ ]*([^\.]*)\.([^ ]*)[ ]out
But if the second part of the expression matches, my () come in under $3 and $4.
Basically, I want to match :
Pin: U713.INP"endofstring or out"
With $1 = U713
$2 = INP
I'm sure there's some simple way to do this and im over complicating it but I cant figure it out for the life of me. A nudge in the rigth dorection would be greatly appreciated. Thanks!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.