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

  • SEARCH
  • Home
  • 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 8472499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:05:34+00:00 2026-06-10T17:05:34+00:00

I have a string that contains 5 words. In the string one of the

  • 0

I have a string that contains 5 words. In the string one of the words is a Ham Radio Call Sign and can be anyone of the thousands of call signs in the US. In order to extract the Call Sign from the string I need to utilize the below pattern. The Call Sign I need to extract can be in any of the 5 positions in the string. The number is never the first character and the number is never the last character. The string is actually put together from an Array since it is originally read from a text file.

$string = $word[1] $word[2] $word[3] etc.... 

So the search can be either done on the whole string or each piece of the array.

Patterns:
1 Number and 3 Letters Example: AB4C A4BC
1 Number and 4 Letters Example: A4BCD
1 Number and 5 Letters Example: AB4CDE

I have tried everything I can think of and search till I cant search no more. I am sure I am over thinking this.

  • 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-06-10T17:05:35+00:00Added an answer on June 10, 2026 at 5:05 pm

    A two-step regular expression like this would do it:

    $str = "hello A4AB there BC5AD";
    $signs = array();
    preg_match_all('/[A-Z][A-Z\d]{1,3}[A-Z]/', $str, $possible_signs);
    foreach($possible_signs[0] as $possible_sign)
        if (preg_match('/^\D+\d\D+$/', $possible_sign))
            array_push($signs, $possible_sign);
    
    print_r($signs); //Array ([0] => A4AB [1] => BC5AD)
    

    Explanation

    This is a regular expression approach, using two patterns. I don’t think it could be done with one and still satisfy the exact requirements of the matching rules.

    The first pattern enforces the following requirements:

    • substring starts and ends with a capital letter
    • substring contains only other capital letters or numbers between the first and last letter
    • substring is, overall, not more than 6 characters long

    What I can’t do in that same pattern, for complex REGEX reasons I won’t go into (unless someone knows a way and can correct me), is enforce that only one number is contained.

    @jeroen’s answer does enforce this in a single pattern, but in turn does not enforce the correct length of the substring. Either way, we need a second pattern.

    So after grabbing the initial matches, we loop over the results. We then apply each to a second pattern that enforces simply that there is only one number in the substring.

    If so, we green-light the substring and it’s added to the $signs array.

    Hope this helps.

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

Sidebar

Related Questions

I have a string, call it paragraph that contains about 50-100 words separated by
If I have a string that contains a url (for examples sake, we'll call
I have a string and it contains some words that I want to reach,
I have a string that contains HTML image elements that is stored in a
I have a string that contains ampersands. I need to escape each ampersand in
I have a string that contains a known number of double values. What's the
I have a string that contains a czech character. the string is 0bálka This
Suppose I have a string that contains Ü. How would I find all those
If I have a string that contains the html from a page I just
If I have a string that contains Cat how could I check before hand

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.