Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Recognizing 3 and 4 digit number

by kcott (Archbishop)
on Jan 03, 2017 at 04:46 UTC ( [id://1178819]=note: print w/replies, xml ) Need Help??


in reply to Re: Recognizing 3 and 4 digit number
in thread Recognizing 3 and 4 digit number

G'day Dave,

At first glance, I thought your regex was better than mine and so I decided to try it. I plugged it into my code but it failed on the phone number and date tests (details in spoiler). The OP requirements are not the best but excluding phone numbers and dates seems to be definitely wanted.

— Ken

Replies are listed 'Best First'.
Re^3: Recognizing 3 and 4 digit number
by davido (Cardinal) on Jan 03, 2017 at 17:53 UTC

    Wah! I guess I got excited and answered before noticing that we wanted to disqualify things that look like phone numbers. Sorry.

    This isn't tested:

    m/(?<![\d-])(\d{3,4})(?![\d-])/

    But it would run afoul of phone numbers using commas to separate, or wrapping parens around area codes.

    It might be useful to take a first pass and keep a list of offsets for "numbers" that should be ignored. It's probably easier to match a phone number with existing libraries than to match a 3 or 4 digit number that is not part of a phone number. In other words, on first pass, identify phone numbers, IP addresses, and other problematic numbers, and push their offsets and lengths into an array. Then on second pass disqualify any number that falls within one of the offset/length sets.


    Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found