Jump to content

Space?


lollipop2468

Recommended Posts

Apologies for the ridiculousness of this question!

 

I am a newbie so please be patient!

 

I am trying to match groups of numbers and letters, however how  do I match a possible space in an expression? By this I mean if a user entered 'ABCD 1234' how can I get it to match with ABCD1234?

 

This is most likely a very simple piece of code - ive searched all afternoon and can not find anything to explain how it is done!

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/261475-space/
Share on other sites

Thanks requinix!

 

Something so simple! I'm trying to learn the basics and struggling to find a guide that explains it easily!

 

So will ' ?' check for either space or no space?

 

If a line was approved as either having/not having a space, is it then possible to strip out the space if you were then going to insert that line into a database?

 

 

Link to comment
https://forums.phpfreaks.com/topic/261475-space/#findComment-1339811
Share on other sites

If a line was approved as either having/not having a space, is it then possible to strip out the space if you were then going to insert that line into a database?

Sure. One way would be to "capture" the letters and numbers, then piece the two parts back together.

 

I felt like drawing some ASCII art. Probably because I'm really tired.

       "ABCD 1234"
         /  |   \
        /   |    \
       V    V     V
    ______      ______
   /      \    /      \
   |      |    |      |
/^([A-Z]{4}) ?([0-9]{4})$/
  |        |  |        |
  \________/  \________/
        \        /
     $1  \      /  $2
          \    /
           V  V
          "$1$2"
            |
            V
        "ABCD1234"

Link to comment
https://forums.phpfreaks.com/topic/261475-space/#findComment-1339869
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.