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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regular expression or the split method?

    Hi,

    The reference-number of products is always product.number, f.e. suncream.1234

    I would like to split every reference-number e.g. the part before the point and the part after.

    What do you recommand to use? regular expressions or the split methode?

    Thanks for Your time,
    Jerome

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Jerome
    regular expressions or the split methode?
    the latter should be sufficient:
    PHP Code:
    alert("product:\t"+initialString.split(".")[0]);
    alert("number:\t"+initialString.split(".")[1]); 
    *keep it simple (TM)

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for Your time and opinion!

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Of course if you wanted to use a regular expression, this would work nicely:

    Code:
    var str = "suncream.1234";
    if( /([a-z_]*).([\d]*)/i.test(str) ) {
    	var strProductName = RegExp.$1;
    	var intProductNumber = RegExp.$2;
    }
    however, it is much of a muchness and jbot has already answered your question, i just like regular expressions

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by martin_narg
    i just like regular expressions
    they certainly have their place, just as nutcrackers and sledgehammers have their's too. just use them wisely, and appropriately.
    *keep it simple (TM)

  • #6
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    very true indeed mate
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

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