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 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts

    A question regarding RegExp

    Is it possible using regExp to check that the numbers in string1 exist in string2 and are in the same order irrespective of the fact that there might be other non-numerical characters mixed in with them
    Last edited by Mr J; 04-17-2005 at 07:41 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes you can.

    feel like providing an example to work from?

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    As you can see the numbers in string 1 are in the same order as in string 2 even though there are other characters present in both strings.

    str1 = "6/3 9-38-4 2/0"

    str2 = "6-3/93-as84/2-0"

    so I am looking to see if 63938420 exists in both strings and in that order


    The numbers themselves may change in value but should be the same in both strings and in the same order

    str1="8-/3 - 6/-2 sd 7bg4"

    str2="8at/3-6 2// 7-4"

    836274 should exist in both string in the same order

    Thank you
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    rgx=/[^0-9]+/g;
    if(str1.replace(rgx,'')==str2.replace(rgx,'')){
      //numerals match!!
      }

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Thank you it worked a treat
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

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