Regular expression problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buntyindia
    New Member
    • Jun 2007
    • 101

    Regular expression problem...

    Hi ,

    I would like to know the meaning of following regular expressions:

    /^((((100)(\\.[0]+)?)|(([0]?\\d{1,2})(\\.[0]+)?))[%]?)$/


    /[\\.]/

    Please reply

    Bunty
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Learn about regular expressions here.

    Comment

    • buntyindia
      New Member
      • Jun 2007
      • 101

      #3
      Originally posted by acoder
      Learn about regular expressions here.
      I already have this link MOD can u please suggest me any community that provide help on Regular expression as this is needed badly

      Thanks,
      Bunty

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What do you not understand about the regular expressions?

        I'm assuming that the double backslashes are not supposed to be there - it should be 1 backslash?

        A quick look: the first one matches 100 followed by either .0 (at least one 0) or nothing OR a 1-3 digit number followed by either .0 or .00(and possibly more 0s) or nothing. Either of those two could also have a %.

        So it would match 100.0, 100.00, 100.0%, 100%, 012.0, 012.0%, 12%, 12, etc.

        The second one matches a dot (assuming one backslash).

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          If you haven't already, you can try out your regular expressions using this tool.

          Comment

          • buntyindia
            New Member
            • Jun 2007
            • 101

            #6
            Originally posted by acoder
            What do you not understand about the regular expressions?

            I'm assuming that the double backslashes are not supposed to be there - it should be 1 backslash?

            A quick look: the first one matches 100 followed by either .0 (at least one 0) or nothing OR a 1-3 digit number followed by either .0 or .00(and possibly more 0s) or nothing. Either of those two could also have a %.

            So it would match 100.0, 100.00, 100.0%, 100%, 012.0, 012.0%, 12%, 12, etc.

            The second one matches a dot (assuming one backslash).
            Thanks Mod it is a Gr8 help...
            earlier this string was used to match whether the entered number in a text box is plain number or number with % sign if it is replace it to decimal point means

            If entered 6 or 6% convert it to 6.0.

            But in case if some one entered 6. (6 with point (.) only) only it should also convert it to 6.0 but it is not converting....

            can you suggest any change to this regular expression.....

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by buntyindia
              Thanks Mod it is a Gr8 help...
              earlier this string was used to match whether the entered number in a text box is plain number or number with % sign if it is replace it to decimal point means

              If entered 6 or 6% convert it to 6.0.

              But in case if some one entered 6. (6 with point (.) only) only it should also convert it to 6.0 but it is not converting....

              can you suggest any change to this regular expression.....
              The regular expression can be used to find a match. To replace, you would use the replace method. Show your code.

              Comment

              • buntyindia
                New Member
                • Jun 2007
                • 101

                #8
                Originally posted by acoder
                The regular expression can be used to find a match. To replace, you would use the replace method. Show your code.

                Actually we use a framework in which code for replacing any string/number is written in core layer of which we don't have access...we can only use some syntax & change Regular expression...
                Code:
                <validator name="pttrnMtchsStrpRplcVld">
                                <constraintData>
                                                <localeConstraint name="pattern" bundle="PatternDecode" key="perctAsIntConstrt" />
                                                <localeConstraint name="stripRegX" bundle="PatternDecode" key="percntStrip" />
                                                <localeConstraint name="replcRegX" bundle="PatternDecode" key="decRepalc" />
                                                <localeConstraint name="replcValRegX" bundle="PatternDecode" key="decReplacVal" />
                                </constraintData>
                                
                </validator>
                in first line we pass the pattern using which to find the string.
                in second line what to strip off
                in third line replace expression
                in fourth with which value to replace etc

                perctAsIntConst rt=/^((((100)(\\.[0]+)?)|(([0]?\\d{1,2})(\\.[0]+)?))[%]?)$/
                #Decimal Replace
                decReplac=/[\\.]/

                #Percent
                percntStrip=/[%]/

                #Decimal Replace Value
                decReplacVal=.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  So you want to match 6, 6% and 6. and replace with 6.0

                  For the 6, you can use \d, but then how many digits can you have? You constrained it to between 1 and 2. The dot and the percent are optional, so we have:
                  Code:
                  ^\d{1,2}(\.|%)?$

                  Comment

                  • chouhan
                    New Member
                    • Jun 2007
                    • 1

                    #10
                    Hi,

                    Here is a url rewriting problem which I have to resolve through Regular Expression.

                    http://www.test.com/cart/index.php?main_ page=index&cPat h=56_57

                    I have to rewrite the above url in the following manner:

                    http://www.test.com/cart/index-main_page-index-cPath-56-57.php

                    could anyone help me plz

                    Regards,
                    chouhan

                    Comment

                    • kovik
                      Recognized Expert Top Contributor
                      • Jun 2007
                      • 1044

                      #11
                      URL Parsing through PHP and PCRE

                      Comment

                      Working...