Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regex: matching any Number then a hyphen

by 1nickt (Canon)
on Nov 27, 2022 at 15:42 UTC ( [id://11148406]=note: print w/replies, xml ) Need Help??


in reply to Regex: matching any Number then a hyphen

Hi,

What did you try? How did it fail?

use strict; use warnings; use utf8; use Test::More tests => 3; for my $line(<DATA>) { chomp $line; my ($string, $wanted) = split '#', $line; $string =~ s/^(\d+)\s*[–-](.*)/$1.$2/; is $string, $wanted; } __END__ 1234 - Foo#1234. Foo 56778 – Bar#56778. Bar 9999. Baz#9999. Baz
Output:
1..3 ok 1 ok 2 ok 3

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2025-07-16 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.