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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.