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 6779609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:24:20+00:00 2026-05-26T16:24:20+00:00

This is a homework assignment and my first experience using RegEx. I am starting

  • 0

This is a homework assignment and my first experience using RegEx. I am starting to grasp the syntax and symbols used and can do some simple pattern matching/manipulation, but can’t quite foresee how to achieve some of the goals of this assignment.

I have been given a text file that is formatted like this:

    Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300
    Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
    Igor Chevsky:385-375-8395:3567 Populus Place, Caldwell, NJ 23875:6/18/68:23400
    Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700

There are about 50 lines of names and corresponding info, each entry is on a new line and each ‘field’ is separated by a colon. Mostly I need to find specific things from the file and print them on a webpage but I don’t quite understand.

Here is one problem I solved:

$myFile = "datebook.txt";
$data = file($myFile);//I have used this to place all data in an array, but it may be necessary to place the data into a string?

//1)    Print all lines containing the pattern Street (case insensitive).
$pattern = "/street/i";
$linesFound = preg_grep($pattern, $data);
echo "<pre>", print_r($linesFound, true), "</pre>";

Here are some I have not and specific questions regarding them:

2) Print the first and last names in which the first name starts with a letter ‘B’.

How do I only search for first names and not last names, city names, etc?

How do I print the full name and only the full name?

5) Print Lori Gortz’s name and address.

I understand how to find the pattern ‘Lori Gortz’ but how do I return her address as well?

11) Print lines that end in exactly five digits.

12) Print the file with the first and last names reversed.

14) Give everyone a $250.00 raise.

Don’t know how to do any of these. I assume the last number for each entry is their salary.

Any help is appreciated. Please respond with an explanation of the code as well, thank you.

  • 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-26T16:24:20+00:00Added an answer on May 26, 2026 at 4:24 pm

    Check the RegEx quick reference, I think you’ll figure out most of your tasks there. For example, Lori’s address would be a string after the number after the second colon and before the second coma (in her line, of course).

    The best way to do all the task would be to go over each line and make an array with all the elements. That way you could easy replace names, increase salaries, check if it ends with 5 digits, etc.

    You can also try this online tester. Good luck.

    Edit:
    Little help for a start:

    ^[A-z ]*   this gets full names
    ^[A-z]*    this gets first names
    etc...
    

    Edit2:
    See what this code does:

    $line = "Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500";
    $regex = "/\s|:/";
    $result = preg_split($regex, $line);
    

    🙂

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

Sidebar

Related Questions

So first off, this is a homework assignment, so please don't write any code
This is for a homework assignment to sort some given strings. I'm prompting the
First of all this is a homework assignment so I'm looking for assistance, not
First of all: this is not a homework assignment, it's for a hobby project
This is part of a homework assignment. I've got several questions asking find the
Disclaimer: This is for a homework assignment, but the question is not regarding the
I'm doing a basic homework assignment which looks like this: While input <> -1
I know this sounds like a homework assignment, but it isn't. Lately I've been
(this is indirectly a part of a much larger homework assignment) I have something
Full disclosure : This is for a homework assignment. This is driving me nuts.

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.