Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2015
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Regular Expression Assistance

    Hi All, I am a VCE Year 12 Software Development student working with PHP. I am having trouble writing a regular expression for a personal project I am working on. Any help is greatly appreciated. Here goes...

    I am trying to write a regular expression to capture each fire brigade that has been paged to an event. There will always be at least one fire brigade , represented by the letter 'C' followed by four letters (CXXXX) for example: CBORT. I can capture one of the groups before capturing the event number (F181209269). The problem is that there may be more than one fire brigade paged or there may only be one.

    I am not sure how to write a regex to capture one brigade or many brigades before capturing the event number. This is what I am dealing with.

    CBORT CKERA F181209269

    (\w+)\s {something goes here to capture just the one brigade or many brigades as individual matches before moving on.} \s(F\d+)

    I don't think I have explained myself very well so please ask all the questions you need and I'll do my best to help you. Thank you for your time!

    Kind Regards,

    Mitch

  2. #2
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Posts
    986
    Thanks
    22
    Thanked 134 Times in 133 Posts
    You could always write a simple explode and for loop.
    PHP Code:
    $columns explode(' ',$rowofdata);
    $firebrigades = [];
    for(
    $i=1;$i<count($columns)-1;$i++) {
      
    $firebrigades[] = $columns[$i];


  3. Users who have thanked Vege for this post:

    Mitchbaker3 (Feb 2nd, 2019)

  4. #3
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,803
    Thanks
    26
    Thanked 602 Times in 595 Posts
    Quote Originally Posted by Vege View Post
    You could always write a simple explode and for loop.
    No need for a loop here...

    PHP Code:
    $firebrigades explode(' '$rowofdata);
    $event array_pop($firebrigades); 
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  5. Users who have thanked Dormilich for this post:

    Mitchbaker3 (Feb 2nd, 2019)

  6. #4
    New to the CF scene
    Join Date
    Nov 2015
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much for your help Vege and Dormilich. I appreciate it!


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •