Loading ...
Sorry, an error occurred while loading the content.

Help with simple RegExp

Expand Messages
  • loro
    Hi, I don t know regular expressions, so please don t laugh too hard!. ;-) I want to find the following. id OR name followed by an equal sign and a single OR
    Message 1 of 6 , Jul 18, 2006
    • 0 Attachment
      Hi,

      I don't know regular expressions, so please don't laugh too hard!. ;-) I
      want to find the following.
      id OR name followed by an equal sign and a single OR double quote and some
      plain text held by a variable. I.e. it should match either of these:

      name="plaintext
      id="plaintext
      name='plaintext
      id='plaintext

      Even better would be if it matched a matching quote at the end too, but I
      didn't get that far. What I came up with on my own actually works in NTP 5
      but in 4.95 it works not.

      (id|name)=("|')\^%variable%


      TIA
      Lotta
    • Don Daugherty
      ... Try changing to (id)|(name)=[ ] ^%variable% or possibly (id)|(name)=[ ] ^%variable% I believe the first part of your expression (in 4.95 at least) looks
      Message 2 of 6 , Jul 18, 2006
      • 0 Attachment
        loro wrote:
        > Hi,
        >
        > I don't know regular expressions, so please don't laugh too hard!. ;-) I
        > want to find the following.
        > id OR name followed by an equal sign and a single OR double quote and some
        > plain text held by a variable. I.e. it should match either of these:
        >
        > name="plaintext
        > id="plaintext
        > name='plaintext
        > id='plaintext
        >
        > Even better would be if it matched a matching quote at the end too, but I
        > didn't get that far. What I came up with on my own actually works in NTP 5
        > but in 4.95 it works not.
        >
        > (id|name)=("|')\^%variable%
        >
        Try changing to

        (id)|(name)=["']\^%variable% or possibly (id)|(name)=["']\\^%variable%
        I believe the first part of your expression (in 4.95 at least) looks for
        "i" followed by "d" OR "n" followed by "ame"
        The ("|') should be ok; ["'] is a construction for situations where the things being OR'd are single characters; [abcd] would mean a|b|c|d for example.
        I think that in 4.95 the extra "\" is needed because a single "\" is a special character that alters the meaning of the character that follows it. To represent a single "\" you double-up: "\\".

        Hope this helps (I haven't tried the new beta, so no knowlege there.)
      • loro
        ... Yes! Thank you! I read about that and still I do it wrong. Funny how blind you are when the stuff is strange to you. ... Yes, parentheses or nothing works.
        Message 3 of 6 , Jul 18, 2006
        • 0 Attachment
          At 18:54 2006-07-18, Don Daugherty wrote:
          >
          >Try changing to
          >
          >(id)|(name)=["']\^%variable% or possibly (id)|(name)=["']\\^%variable%
          >I believe the first part of your expression (in 4.95 at least) looks for
          >"i" followed by "d" OR "n" followed by "ame"

          Yes! Thank you! I read about that and still I do it wrong. Funny how blind
          you are when the stuff is strange to you.

          >The ("|') should be ok; ["'] is a construction for situations where the
          >things being OR'd are single characters; [abcd] would mean a|b|c|d for example.

          Yes, parentheses or nothing works. The square brackets didn't.

          >I think that in 4.95 the extra "\" is needed because a single "\" is a
          >special character that alters the meaning of the character that follows
          >it. To represent a single "\" you double-up: "\\".

          I don't think it's needed at all, works the same without. Notetab probably
          interprets the variable first. I left it in just to be safe (and because
          it's about the only regexp character that I know what it means ;-o))
          (id)|(name)="|'^%variable%

          >Hope this helps (I haven't tried the new beta, so no knowlege there.)

          Sure did. Thanks again. :-)

          Lotta
        • Gary Oliver
          ... ;-) I ... and some ... but I ... NTP 5 ... Here is an example I hope this reply does not mess up the line breaks much but I think you will understand.
          Message 4 of 6 , Jul 18, 2006
          • 0 Attachment
            --- In ntb-clips@yahoogroups.com, loro <loro-spam01-@...> wrote:
            >
            > Hi,
            >
            > I don't know regular expressions, so please don't laugh too hard!.
            ;-) I
            > want to find the following.
            > id OR name followed by an equal sign and a single OR double quote
            and some
            > plain text held by a variable. I.e. it should match either of these:
            >
            > name="plaintext
            > id="plaintext
            > name='plaintext
            > id='plaintext
            >
            > Even better would be if it matched a matching quote at the end too,
            but I
            > didn't get that far. What I came up with on my own actually works in
            NTP 5
            > but in 4.95 it works not.
            >
            > (id|name)=("|')\^%variable%
            >
            >
            > TIA
            > Lotta
            >

            Here is an example I hope this reply does not mess up the line breaks
            much but I think you will understand. straighten out the line break
            issues in this post and this works as a clip.

            find a variable
            ;in 4.95pro
            ^!set %cssitem%=pagewidth
            ^!find "(id=["']?^%cssitem%["']?)|(class=["']?^%cssitem%["']?)" RIS
            ;RIS means regular expression case in sesitive silent or don't stop if
            error
            ;the above find transalted into natural language
            ;find id= with either 0 or 1 sigular quote or double quote and
            ^%cssitem% ending with 0 or 1 sigular quote or double. OR find class=
            with either 0 or 1 sigular quote or double quote and ^%cssitem% ending
            with 0 or 1 sigular quote or double.

            ;A replace statement that finds all of the same thing and remembers
            the type of quote mark and outputs all as class= with the correct
            quote type
            ;^!replace
            "(id={["']?}^%cssitem%["']?)|(class={["']}?^%cssitem%["']?)" >>
            "class=\1^%cssitem%\1" RAIS

            Gary O
          • loro
            ... ... I see how that works, I think. Thanks! I actually have a beginner book on regexp, but it s easier to find something in it when I have a starting
            Message 5 of 6 , Jul 19, 2006
            • 0 Attachment
              Gary Oliver wrote:
              >Here is an example I hope this reply does not mess up the line breaks
              >much but I think you will understand. straighten out the line break
              >issues in this post and this works as a clip.
              <snip>
              >^!find "(id=["']?^%cssitem%["']?)|(class=["']?^%cssitem%["']?)" RIS

              I see how that works, I think. Thanks! I actually have a beginner book on
              regexp, but it's easier to find something in it when I have a starting
              point. I'll go dust it off now and look what it has to say about the things
              I've learnt.

              Lotta
            • abairheart
              ... but I ... The OR functions applies only to the nearest expression. In the above case, that is the d of id, and the n of name. As already suggested:
              Message 6 of 6 , Jul 19, 2006
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, loro <loro-spam01-@...> wrote:
                >
                > Hi,
                >
                > name="plaintext
                > id="plaintext
                > name='plaintext
                > id='plaintext
                >
                > Even better would be if it matched a matching quote at the end too,
                but I

                > (id|name)=("|')\^%variable%

                The OR functions applies only to the nearest expression.
                In the above case, that is the "d" of id, and the "n" of name.

                As already suggested:

                (id)|(name) corrects that part.
                Now the expressions adjacent to the OR function "|" is the entire
                content of each parentesis group.

                The rest of the expression, including the ending quote,
                can be handled by a NOT character set [^character set].

                (id)|(name)="[^"]*"

                This searches for id or name, followed by '="' followed by
                anything BUT a quote, followed by a closing quote.



                Abair
              Your message has been successfully submitted and would be delivered to recipients shortly.