Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6968861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:30:23+00:00 2026-05-27T16:30:23+00:00

For learning purposes I am implementing a little regexp matcher for telephone numbers. My

  • 0

For learning purposes I am implementing a little regexp matcher for telephone numbers. My goal is readability, not the shortest possible gawk program:

# should match
#1234567890
#123-456-7890
#123.456.7890
#(123)456-7890
#(123) 456-7890 

BEGIN{
    regexp="[0-9]{10},[0-9]{3}[-.][0-9]{3}[.-][0-9]{4},\\([0-9]{3}\\) ?[0-9]{3}-[0-9]{4}"
    len=split(regexp,regs,/,/)
}
{for (i=1;i<=len;i++)
    if ($0 ~ regs[i]) print $0
}

For better readability I would like to split the line regexp="... on several lines like:

regexp="[0-9]{10}
       ,[0-9]{3}[-.][0-9]{3}[.-][0-9]{4}
       ,\\([0-9]{3}\\) ?[0-9]{3}-[0-9]{4}"

Is there an easy way to do this in awk?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:30:24+00:00Added an answer on May 27, 2026 at 4:30 pm

    The concensus seems to be that there is no simple way to split multiline strings without disturbing awk? Thanks for the other ideas, but make me as the programmer do the work of the computer what i don’t enjoy. So i came up with this solution, which in my opinion is pretty close to a kind of executable specification. I use the base and here documents and process redicrection to create the files for awk on the fly:

    #!/bin/bash
    
    # numbers that should be matched
    read -r -d '' VALID <<'valid'
    1234567890
    123-456-7890
    123.456.7890
    (123)456-7890
    (123) 456-7890 
    valid
    # regexp patterns that should match
    read -r -d '' PATTERNS <<'patterns'
    [0-9]{10}
    [0-9]{3}\.[0-9]{3}\.[0-9]{4}
    [0-9]{3}-[0-9]{3}-[0-9]{4}
    \([0-9]{3}\) ?[0-9]{3}-[0-9]{4}
    patterns
    
    gawk --re-interval 'NR==FNR{reg[FNR]=$0;next}
      {for (i in reg) 
        if ($0 ~ reg[i]) print $0}' <(echo "$PATTERNS") <(echo "$VALID")
    

    Any comments are welcome.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on implementing my own Trie in Scala (for learning/hobby purposes), and
For learning purposes I'm building a simple messaging program that I think can work
I've written a Task Scheduling program for learning purposes. Currently I'm saving the scheduled
I want to build a little app for myself (learning purposes) for the service
I was implementing a small library for testing purposes an learning about event handling
I'm writing a program(just for learning purposes, I want to learn C++) in the
I have a program that I am reverse engineering for learning purposes about protocols
I'm looking through some code for learning purposes. I'm working through this portion of
I'm trying to develop a personal MVC framework for learning purposes. But every time
I'm trying to setup a new web-application for learning purposes using the newest technologies:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.