Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Problem with regexp to match

by LanX (Saint)
on Oct 14, 2021 at 15:31 UTC ( [id://11137516]=note: print w/replies, xml ) Need Help??


in reply to Problem with regexp to match

One of the obvious problems is, that you want to use slashes inside your regex without escaping them.

/ --> \/

If I where you I'd change delimiter and try m{REGEX} instead of m/REGEX/ .

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

there where more issues, but this works for me ( perl -dE0 starts the debugger )

DB<25> @m = qw{01/LC-13/E10GbE-1 01/LC-13/E10GbE-1,01/LC-14/E10GbE- +1} DB<26> say join ":", m{\d\d/\w+-(\d+)/\w+-(\d+),?}g for @m 13:1 13:1:14:1 DB<27>

update

If the snippets don't always start with \d\d change it to \d+

If I where you I'd consider spliting on , and then / .

Then applying a simple regex, should be more stable and maintainable.

Replies are listed 'Best First'.
Re^2: Problem with regexp to match
by Bod (Parson) on Oct 14, 2021 at 17:36 UTC
    If I where you I'd change delimiter and try m{REGEX} instead of m/REGEX/

    Completely agree.
    When it was first recommended to me that I make this change, I thought it wouldn't make much difference. In fact it has had a significant effect on the legibility and maintainability of my code.

    One of the many fabulous suggestions from the Monastery.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found